Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java Programming Code HELP
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Lisa
Java Programming Code HELP
0 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


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();

  }

}

Advertisement
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... and terminating the application. Regards!   Hi Friend, Try the following code
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
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 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
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
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
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 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 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  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 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
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
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 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 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 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 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 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 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
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
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
Advertisements
 

 

 

DMCA.com