Home Answers Viewqa Java-Beginners Java Programming Code HELP

 
 


Lisa
Java Programming Code HELP
0 Answer(s)      2 years and 5 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();

  }

}
View Answers









Related Pages:
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
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
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
help
(); } } SFDV2103 â?? Java Programming Fall, 2012 Term Project... on the percentage of cheating. SFDV2103 â?? Java Programming Fall, 2012 Term... for the above. You must submit the source code to your teacher by printing the programs
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
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 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
help
help  pls help me to get the code of a java program a program to perform different shapes in a menu using javaapplet
help
help  i need help with this code. write a java code for a method named addSevenToKthElement that takes an integer array, and an integer k as its arguments and returns the kth element plus 7. 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 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 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
Programming
Programming  how to save output of java file in .txt format?  ...; bracket to direct the output to a text file. Here is the example: C:>java...(); } } Is this code is beneficial for you. For further issues feel free to ask
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 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
Java application  public int remainder(int a, int b...!  We have modified your code. The character you want to display in the printf method is actually invalid.Therefore error occurs. Anyways, check your code
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
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
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 - Java Beginners
java programming  i'm asking for the java code for adding , viewing... a code..help me plzz  Hi Friend, Please go through the following links: http://www.roseindia.net/java/example/java/swing/add_edit_and_delete
java programming code - Java Beginners
java programming code  Design and write a Java application that takes as input a single letter and displays the corresponding digit on the telephone...;Hi Friend, Try the following code: import java.util.*; import
java programming - Java Beginners
java programming  hi sir, i hav send u a code jus now regarding that program but it tends to be having error. Can u help me check? And still not sure whether some place got error
java programming - Java Beginners
is write a program in java to print * * * * * * * * * * the o/p will come like that structure   Hi friend, Code to help...java programming  Hi Buddies, i want java Array ,looping
Java programming
common programming errors. Java programming source code files are compiled into a format called byte code, which can then be executed by a Java programming... support examples related to each Java programming technology that will help
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 4.2 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... of cases. A little creative cut-and-paste can help. The switch statement has
help - Java Beginners
, and this is very similar to C++. Java Programming Language is simplified to eliminate language features that cause common programming errors. Java source code..., Java : Java is great programming language for the development of enterprise
java programming - Java Beginners
java programming  asking for java code .. counting for how many times... -- 1 help me plz... thank u ahead   Hi Friend, Try the following code: import java.util.*; public class CountCharacters { public static
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
ajax programming
is based on the HTML, Java Script, CSS, and XML. Why Ajax Programming? When you...Ajax Programming What is Ajax Programming? Asynchronous JavaScript and XML.... Easy to learn and easy to write technology. Where to Start Ajax Programming
Java help - Java Beginners
Java help  I didnot get the code ,therefore I am posting my question again.. Thanks in advance ...:) Programming Assignment: A) Consider the outpatient pharamacy at University Hospital. At the entrance of the pharmacy
java programming problem - JDBC
java programming problem  Hi, Request you to provide a solution ( analysis & design & unit test plan & code & test criteria ) to the following... database using java / j2ee. mail id : raichallp@yahoo.co.in
Java Programming using array
Java Programming using array  I'm creating a programming using array...("Wrong Input!"); } } Help me out please.   hi friend, Try this sample code may, this will be helpful for you. package net.roseindia
Programming Difficulty - Java Beginners
; Hi friend, Code to help in read the text file...Programming Difficulty  Suppose that a file named "testdata.txt" contains the following information: The first line of the file is the name
mobile programming - Java Beginners
mobile programming  hai sir i need ur help... i need source code j2me about bike racing game.. coming Wednesday i have to submit the project.. so plzz send me the coding bike racing as soon.... thank you sir
java programming - Spring
java programming  please i want your help and solution also in this example: using JCreatorPro program Write a Java program that does...; Hi Friend, Try the following code: import java.util.*; class Input
need help - Java Beginners
need help  Need help in programming in Java  Simple java program that will show the output within quotes using system.out.println... the following code is this: public class print1{ public static void main(String
help - Java Beginners
help  The programming task You are to write a Java application... will help you. Please visit : http://www.roseindia.net/java/java-conversion... 01110011. In this assignment, you must read the original decimal number in as a Java
Swing programming - Java Beginners
someone help me.  Hi Friend, We have modified your code,try... { JFrame f = new JFrame("Frame in Java Swing"); f.getContentPane... in Java Swing"); f.getContentPane().setLayout(null); JLabel lbl1 = new JLabel
plz help - Java Beginners
Thread in java : First Code : import java.io.PrintWriter; import... got a solution that makes programs run much faster which is threading programming.. but i dont know how to aplly that on my 2 programs: the first code
program help - Java Beginners
, Abstract Class In java programming language, abstract classes are those...program help  In the following code, I want to modify class figure.... For read more information on java visit to : http://www.roseindia.net/java
code
code   hi I need help in creating a java code that reminds user on a particular date about their festival. i have no clue of how to do it.. am looking forward to seek help from you
java programming
java programming  how to count the no. of constants in a user given string?? plzz help
Java Programming
Java Programming  Using Java Frame form, help me develop a GPA calculating device, able to show Grade and points together, and using MySQL database
Java Programming
Java Programming  Using Java Frame form, help me develop a GPA calculating device, able to show Grade and points together, and using MySQL database
java help
java help  How to Open CSV Files in a Microsoft Excel Application Using Java Code with example pgm
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