Java Programming Code HELP

Java Programming Code HELP

Hi, sir/madam.

I am new here and currently developing a program whereby it can read the Java source file and then display all the String into tokens. Class Name , attribute and methods are being extracted out respectively throughout the execution. However, I now face the problem to retrieve the attribute name and method name. I have manage to pull out the Class name but now I am stuck at pull out the attribute name. (For example, type: String, attribute name = variable name)

Below are my source code. Hope the expert can help me to solve this problem and pull out the attribute name. Can sir/madam help me check where is the problem...and help me to fix it..thanks a lot..

import java.util.*;
import java.io.*;

public class Java2UML {
   private static final int INITIAL              = 0;
   private static final int COMMENT              = 1;
   private static final int SCANNED_CLASS        = 2;
   private static final int SCANNED_ATTRIBUTE    = 3;
   private static final int SCANNED_METHOD       = 4;
   private static final int READING_CURLYBRACKET = 5;
   private static final int READING_ACCESS_SPECIFIER   = 6;
   private static final int READING_ATTRIBUTES   = 7;


   private String filename; //declare the variable filename of type String
   private Scanner sc;
   String className;
   String attributeName;

   Java2UML ( String name ) {
      filename = name; 
   }

   public void openFile() throws IOException {
     System.out.println( "File: " + filename ); 
     sc = new Scanner( new File ( filename )  );
   }

   public void readFile() {
     while (sc.hasNextLine() ) {
        String line;
        line = sc.nextLine();       

        tokenize(line);
     }
   }

  /************************
   * tokenizes a single line, which is passed in as a parameter.
   */  
  public void tokenize(String line)   {
     String token;
     int scanState = INITIAL;
     StringTokenizer st = new StringTokenizer( line, "; "  );

     while (st.hasMoreTokens()) {
        token = st.nextToken();

          if (token.equalsIgnoreCase( "//" )) {
            // we've seen the beginning of comment.
            scanState = COMMENT;
        } else if (token.equalsIgnoreCase( "CLASS" ))  {
            scanState = SCANNED_CLASS;
            continue;      
        } else if (token.equalsIgnoreCase( "PRIVATE" )) {
            scanState = READING_ACCESS_SPECIFIER;
            continue;
        } else if (token.equalsIgnoreCase( "PUBLIC" ))  {
            scanState = READING_ACCESS_SPECIFIER;
            continue;
        } else if (token.equalsIgnoreCase( "PROTECTED" )) {
            scanState = READING_ACCESS_SPECIFIER;
            continue;
        } else if (token.equalsIgnoreCase( "PRIVATE" )) {
            scanState = READING_ACCESS_SPECIFIER;
            continue;
        }




        switch (scanState) {
          case Java2UML.COMMENT: continue;

          case Java2UML.SCANNED_CLASS:
                      className = token;
                      drawClass(className); 
                      scanState = READING_CURLYBRACKET;
                      continue;

          case Java2UML.SCANNED_ATTRIBUTE:
                      attributeName = token;
                      drawAttribute(attributeName);
                      scanState = READING_ATTRIBUTES;
                      continue;

        }

        System.out.println("This is a token <" + token + ">");

    }


  }

  public void drawClass(String className) {
    System.out.println( "---------------------------" ); 
    System.out.println( "CLASS NAME IS : " + className );
    System.out.println( "---------------------------" );
  }

  public void drawAttribute(String attributeName) {
    System.out.println( "---------------------------" ); 
    System.out.println( "ATTRIBUTE IS : " + attributeName );
    System.out.println( "---------------------------" );
  }


  public static void main (String args [])throws Exception{
    Java2UML x; 
    x = new Java2UML ( "Java2UML.java" ); 
    x.openFile();
    x.readFile();

  }

}
View Answers

Ads









Related Tutorials/Questions & Answers:
Java Programming Code HELP
Java Programming Code HELP  Hi, sir/madam. I am new here and currently developing a program whereby it can read the Java source file...: String, attribute name = variable name) Below are my source code. Hope
Java Programming Help
Java Programming Help  Hello ! I m the student of last year and i need your help to complete my java project. I going to make a site like youtube... with paging. Q2: I want the code and idea about to "When user can click
Advertisements
Need Help in Java programming
Need Help in Java programming  Hello. Can someone please help me with writing the following program Java program that gives assignment details such as:assignment number,assignment name,due date,submission date,percentage marks
java programming code
java programming code  strong textHi I need the java code for the folllowing java output can you help me?The user inputs for the program are in inverted commas thank you. Blockquote HARDWARE ITEMS CODE DESCRIPTION UNIT
Java programming using ArrayList Help?
Java programming using ArrayList Help?  Hi,can anybody help and guide me on doing this java program? (Largest rows and columns)Write a program... The largest row index : 2 The largest column index : 2,3 Any help would be greatly
Java programming using ArrayList Help?
Java programming using ArrayList Help?  Hi,can anybody help and guide me on doing this java program? (Largest rows and columns)Write a program... row index : 2 The largest column index : 2,3 Any help would be greatly
Java Programming Need Help ASAP
Java Programming Need Help ASAP  You are required to develop a student menu system that is similar to the bank system covered in class..., their year (you can assume they all start in year 1), their programming mark
help to write java code
help to write java code  write a full code to produce a system will calculate all items to get total carry-marks which are 60 marks. and get sum of assignment 1,assignment 2, midterms-test and lave work to get total marks
help to write java code
help to write java code  write a full code to produce a system will calculate all items to get total carry-marks which are 60 marks. and get sum of assignment 1,assignment 2, midterms-test and lave work to get total marks
Craps Game Java Programming Help
Craps Game Java Programming Help  Craps is a casino game that involves the throwing of a pair of dice. Based on the throw, the thrower either gets... roll. You may wish to print the roll sequence to help you debug. Output
Urgent java programming question.Pls help
Urgent java programming question.Pls help  Q1. Generate 10 thousand random integers with values in the range between 1 to 100. Q2. Store each randomly generated number into a node and then attach the node to a linked list
Java code help
Java code help  Write a java program that will ask the user to input any number from 5 to 9 and then print the following structure depending on the user input. E.g. If the user input is 5, then print the following structure 1 2 3
Java File Programming
Java File Programming articles and example code In this section we will teach you about file programming in your Java applications. Java File Programming... program. Java programming language provides many API for easy file management. Java
code for programming
code for programming   One fine day, Jack decided to complete his summer vacation assignment, to draw the view of the city which he gets from his..., Height = 11 and Breadth= 5. send me the code for this question ASAP.  
Help on this java code for online library search
Help on this java code for online library search   I have written the following java code for simple library book search. but its having some errors ... please help me on this code. import java.sql.*; import java.awt.
Please help me to modify my java code from php code
Modify Java code from PHP Code  i want to covert this php code int java/JSP. if (isset($_POST['orders'])) { $orders = explode('&', $_POST... the exact result as the above PHP code is giving. So please help me to convert
Please help me to modify my java code from php code
Please help me to modify my java code from php code  i want to covert this php code int java/JSP . if (isset($_POST['orders'])) { $orders... help me to convert it into Java. if (request.getParameter("orders") != null
hi need help with C++ programming!
hi need help with C++ programming!  how do i : b. Store numbers / characters into the file (output) c. Retrieve numbers / characters from the file (input thanks!   b) #include <iostream> #include <
Help in completing Servlet code!
Help in completing Servlet code!  Complete the following Servlet codes to store the information read from the input form to session object. public... String comment = req.getParameter(?commentText?); //Complete the code to store
FTP Programming in Java tutorials with example code
FTP Programming in Java In this tutorial series of Java programming we are now continuing with the FTP Programming in Java. With the help of these tutorials... Programming in Java: What is FTP (File Transfer Protocol)? What is Anonymous FTP
Code Help Needed
Code Help Needed  I am trying to help a buddy of mine with this program and I can't seem to figure it out. I am still working on it but any help...[test]); line. Again thank you for any help. import java.util.*; import
Please help with this code
Please help with this code  I need some help getting the Search method below to work with the menu, and I also cannot figure out how to get my bubble sort to work. I've spent a long time on this and think my brain is just fried
more code help
more code help  Instructions: Write a program to translate a message from English to Morse code. Using a simple text editor like Windows Notepad, create a text file with all of the Morse code combinations for the letters
I need help on my Java code.... please please help me out!?
I need help on my Java code.... please please help me out!?  Well my code is supposed to ask for an input file and then (ex: input.txt), read... in the file. Also it should be displayed on the screen. However my code doesn't display
need someone to do/help with code
need someone to do/help with code  i need someone to do a code for me. It is a restaurant menu that displays a list of 10 food items. A customer..., along with the number of items sold..please help did a code 500 times cant
java programming code to upload a dataset(text file) and show the values in graphically view
java programming code to upload a dataset(text file) and show the values in graphically view  how can be done upload a dataset(text file) and show the values in graphically view,,related to slam benchmarking java code
Java Programming
Java Programming  Hi, What is Java Programming? How I can learn Java Programming in one month? Thanks
Learn Java Programming for beginners
Java programming tutorials for beginners for learning Core Java, Advanced... programming language for beginners which teaches you Java programming language. Java programming language is very popular language and its on high demand
could anyone please help with the code.
could anyone please help with the code.  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException...(request, response); } } could anyone please check the code. If i enter
ajax code please help to solve this........
ajax code please help to solve this.  in this i am trying to get data... to database and retrieve viewbirthapplicants.jsp <%@ page language="java...;<a href="help.jsp">help instruction</a></li> <
Encapsulation in Java Programming
will explain you the Encapsulation concept of the Java Programming language... hiding. Video tutorial of Encapsulation in Java Programming: Advantage... format. Check all the Video tutorials of the Java Programming Language

Ads