using TreeMaps and Hashsets (Written in Java) home / study / questions and answers / engineering / computer science / using treemaps and hashsets i need to write a program ... Question Using TreeMaps and Hashsets I need to write a program that will read a java source code file and output a list of all identifiers(variables, method names, class names, fields..) but NOT KEYWORDS and NOT WORDS FOUND IN STRING CONSTANTS. All of these listed in lexicographical order(Based on unicode) Each Indentifier should be output with a list of the line numbers on which it occurs. The program should either ask the user for a input file or make the filemame a command line parameter. Have your program prompt the user for a name of a Java program (or take the name of the program as a command line parameter) Create a BufferedReader with this file name. Before you begin to read the program, place all the Java keywords from the keywords.dat file in a HashSet of Strings, so you will know which words to skip. Using the StateMachine read the identifiers one at a time. The program should store all non-keyword identifiers in a Java TreeMap class. The key should be the identifier(which is a String), and the data should be a Linked List containing the line numbers as the data. If an identifier is read for the first time, a new linked list should be created, the current line number added to the list, and then the identifier with its list should be added to the TreeMap. If the identifier has already been seen, just add the current line number to its LinkedList
There is a Folder with some files that should be used in Conjunction with the program. The StateMachine.java class that will help with the reading of the file. You do not need to modify any of the files included just create a program that uses these files appropriately. StateMachine.java has these three public methods: 1. StateMachine(BufferedReader input) : constructor that takes a BufferedReader (that has already been created) as a parameter. 2. boolean hasNextToken() : returns whether or not there is another identifier or keyword in a the file 3. String getToken() : returns the next identifier or keyword in the input file (skips over punctuation and quoted Strings 4. int getLineNumber(): returns the line number of the last token that was returned. There is a Tester class to show how to use the StateMachine class. Its main method requires a filename as a command-line parameter. It simply prints all the tokens in a .java file with their line numbers (note it includes keywords.) Here is a suggestion for your program: Have your program prompt the user for a name of a Java program (or take the name of the program as a command line parameter) Create a BufferedReader with this file name. Before you begin to read the program, place all the Java keywords from the keywords.dat file in a HashSet of Strings, so you will know which words to skip. Using the StateMachine read the identifiers one at a time. The program should store all non-keyword identifiers in a Java TreeMap class. The key should be the identifier(which is a String), and the data should be a Linked List containing the line numbers as the data. If an identifier is read for the first time, a new linked list should be created, the current line number added to the list, and then the identifier with its list should be added to the TreeMap. If the identifier has already been seen, just add the current line number to its LinkedList