Problem Statement: In this project, you are asked to write a Java application th
ID: 3832351 • Letter: P
Question
Problem Statement:
In this project, you are asked to write a Java application that utilizes your knowledge about a number of data structures we have been discussing throughout the course of this semester. The main task of this application is to automatically generate a book index for a given arbitrary text file.
As you know, a traditional book index lists on which page each important/key word occurs. In the application that you will develop, you are required to generate an index for ALL words in the given file. To standardized testing of all students’ submissions, all of you are required to use the given text file posted online next to this project statement. The file name is “alice30.txt” and it contains the famous Alice in Wonderland book that is freely available via Project Gutenberg. The simple given test file that you MUST use does NOT have page numbers and thus you will use chapters instead in your indexing.
While considering which data structure that can best fit this application, please remember that your index will look similar to the following:
“Keyword”{2, 3, 7, 9}
Where “keyword” is the word that you are trying to index and {2, 3, 7, 9} is the set of chapters that “keyword” occurs in. In other words, “keyword” occurs in chapters 2, 3, 7, and 9. If a keyword occurs multiple times in the same chapter, your index will ONLY list the chapter one time and thus maintain the set property. The structure of such index can be implemented using a Map whose keys are the Strings representing the words that you are indexing and the value associated with each key is a set of integer values denoting which chapters a particular key word occurs. Hint: your main data structure can take the following form. The choice of TreeMap and TreeSet will ensure that the data stored in these structures are sorted.
TreeMap>
Your code is expected to have two files with the following functionalities:
A Driver program that will create a Scanner object to open the given input file and make sure that ALL non-alphabetical characters are skipped. To do that you need to use the appropriate regular expressions with the .useDelimiter() method of the scanner class. Then, all data from the input file will be read and converted to lower case. The driver program will then invoke the appropriate methods from the MainIndexingClass to generate the desired index then display the generated index on the monitor.
A MainIndexingClass file that defines the selected data structure then provides appropriate constructor to initialize that TreeMap. This class also will provide all needed functionalities to generate and maintain the required index structure.
Explanation / Answer
The expected outputs are:
Comments
Comments are used to document and explain your codes and your program logic. Comments are not programming statements. They are ignored by the compiler and have no consequences to the program execution. Nevertheless, comments are VERY IMPORTANT for providing documentation and explanation for others to understand your programs (and also for yourself three days later).
There are two kinds of comments in Java:
I recommend that you use comments liberally to explain and document your codes. During program development, instead of deleting a chunk of statements irrevocably, you could comment-out these statements so that you could get them back later, if needed.
Statements and Blocks
Statement: A programming statement is the smallest independent unit in a program, just like a sentence in the English language. It performs a piece of programming action. A programming statement must be terminated by a semi-colon (;), just like an English sentence ends with a period. (Why not ends with a period like an English sentence? This is because period crashes with decimal point - it is hard for the dumb computer to differentiate between period and decimal point in the early days of computing!)
For examples,
Block: A block is a group of statements surrounded by a pair of curly braces { }. All the statements inside the block is treated as one single unit. Blocks are used as the body in constructs like class, method, if-else and for-loop, which may contain multiple statements but are treated as one unit (one body). There is no need to put a semi-colon after the closing brace to end a compound statement. Empty block (i.e., no statement inside the braces) is permitted. For examples,
public class OddEvenSum { // Save as "OddEvenSum.java" public static void main(String[] args) { int lowerbound = 1, upperbound = 1000; int sumOdd = 0; // For accumulating odd numbers, init to 0 int sumEven = 0; // For accumulating even numbers, init to 0 int number = lowerbound; while (number <= upperbound) { if (number % 2 == 0) { // Even sumEven += number; // Same as sumEven = sumEven + number } else { // Odd sumOdd += number; // Same as sumOdd = sumOdd + number } ++number; // Next number } // Print the result System.out.println("The sum of odd numbers from " + lowerbound + " to " + upperbound + " is " + sumOdd); System.out.println("The sum of even numbers from " + lowerbound + " to " + upperbound + " is " + sumEven); System.out.println("The difference between the two sums is " + (sumOdd - sumEven)); } } Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.