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









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
Need help in java programming
Need help in java programming  Hello. Can someone please help me... 10% Exam 60% Java program that accepts the following details: student..._TO_REPLACE_2 Try the following code: import java.util.*; public class
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
programming code - Java Beginners
programming code  program code for converting temperature from... or fahrenheit is entered   Hi Friend, Try the following code. I will really help you. import java.io.*; import java.util.*; class
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 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 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
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
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
Java programming help - Java Beginners
Java programming help  Write a program that asks the user for an integer, and if the input is positive, puts stars on the screen - one star on line... for more information. http://www.roseindia.net/java/ Thanks
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 programming code - Java Beginners
java programming code  I want to write a program that converts temperatures from celsius to fahrenheit and vice versa. It also converts kilometers to miles and vice versa using classes
java programming code - Java Beginners
java programming code  Design and write a Java application that takes... No digit corresponds to either Q or Z. For the two letters, your application should...;Hi Friend, Try the following code: import java.util.*; import
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
Java programming help with files - Java Beginners
Java programming help with files  I want a code or the following program .thanks Write a program that reads employee data into a vector. The data is composed of : - id# - name - nationality - job title the program
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.  
Plz help me in writing the code - Java Beginners
Plz help me in writing the code   Write a two user Chess Game. (users must be on different systems
Plz help me in writing the code - Java Beginners
Plz help me in writing the code   Write a two user Chess Game. (users must be on different systems
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 give code - Java Beginners
please help me to give code  Write a program that prints an n-level stair case made of text. The user should choose the text character..., http://www.roseindia.net/java
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 give code - Java Beginners
please help me to give code  Write a program that reads a file named famous.txt and prints out the line with the longest length. In the case...(); } } } ------------------------------- read for more information, http://www.roseindia.net/java/beginners/read
please help me to give code - Java Beginners
please help me to give code  Write a function, sliding(word, num)that behaves as follows. It should print out each slice of the original word having length num, aligned vertically as shown below. A call to sliding(examples, 4
please help me to give code - Java Beginners
please help me to give code  Write a function with a signature cheerlead(word) that prints a typical cheer as follows. The word robot: Gimme an R Gimme an O Gimme a B Gimme an O Gimme a T What did you give me? ROBOT
please help me to give code - Java Beginners
please help me to give code  Write a program that uses loops to generate an n x n times table. The program should get n from the user. As a model here is a 4 x4 version: | 1 2 3 4
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
Programming Help URGENT - JSP-Servlet
Programming Help URGENT  Respected Sir/Madam, I am... CODE... TO ROSEINDIA TEAM< IF I GET THIS HELP IN TIME.... Thanks/Regards
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... and examples of FTP Programming in Java: What is FTP (File Transfer Protocol)? What
Calender code ! HELP!!!
Calender code ! HELP!!!  how can i add 3 days to current date ? i am.... i am working on a school project & i really need help on this!!!ADS_TO_REPLACE_1 Please help me. This is my code: var Calendar = Class.create();ADS
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
Pleae help me to give logic and code for this program - Java Beginners
Pleae help me to give logic and code for this program  Write a function that given the string ?original? create a new string ?dramatic? that has two...://www.roseindia.net/java/beginners/StringReverseUsingStringUtils.shtml
game programming code - Swing AWT
game programming code  write a snake program using swings with step by step explanation?. please send me this source code to my mail id with step by step explanation
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
Programming help Very Urgent - JSP-Servlet
Programming help Very Urgent  Respected Sir/Madam, Actually my code shows the following output: There is a combo box which contains all the ID's... code: EMPLOYEE DETAILS Enter Employee ID
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
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
Java Programming  Hi, What is Java Programming? How I can learn Java Programming in one month? Thanks
help in insert code - JSP-Servlet
help in insert code  I have some doubt in following code. I want to insert value using prepared statement.we r accessing connection from other package.can u plz help me out.  hiimport java.io.*;import java.sql.*;import
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
Encapsulation in Java - One of the 4 OOPs concept In this video tutorial I will explain you the Encapsulation concept of the Java Programming language... Check all the Video tutorials of the Java Programming Language
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

Ads