Templates are provided below for implementing the program as two separate files a test driver class

Page 1

Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence To Purchase This Material Click below Link http://www.tutorialoutlet.com/all-miscellaneous/templates-are-provided-belowfor-implementing-the-program-as-two-separate-files-a-test-driver-class-containingthe-main-method-and-a-sentence FOR MORE CLASSES VISIT tutorialoutlet

Product Description For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting the input file name as a command line argument to the program. This will allow the graders to test your program against several different input files. You will not know in advance the input file names that the graders will use. It is your job to add the necessary code to the templates to make the program process the input to produce the required output. Detailed instructions for each class are provided below. The input file will be in the format specified below. A sample input file that you can use for development is also described below. However, we will test the program with different input files with different names, so you should not hard code any file name in your program. Program output must be to the console (screen) and must conform to the format requirements that are also specified below. For your development testing purposes, the sample program output below corresponds to the sample input file described


in this assignment. NetBeans Project Setup 1. Create a Java application project called ”SentenceUtils" in NetBeans. Edit the project's packaging properties so that the source (.java) files will be included in the JAR file. 2. Create a Java package called ”sentenceutils" in this project if the package was not already created for you by NetBeans. 3. If NetBeans automatically created a SentenceUtils.java file for you, delete it. 4. Create a regular Java class file called ”SentenceUtilsTest.java" in the sentenceutils package. This is the test driver file that will contain the main() method for the program. Then, enter all of the code from the following template, including the file header with your name: 5. Create a regular Java class file called ”SentenceUtils.java" in the sentenceutils package. This is the sentence utilities file. Each instance of this class will represent one sentence and will be responsible for determining its tokens and shingles, and for reporting their values. Then, enter all of the code from the following template, including the file header with your name: 6. Create the file "cosmic" in your project at the top level. The name of the file should be "cosmic", not "cosmic.txt". Just right-click on the project name and select New/Other, then the "Other" category and finally "Empty file". Add the following data entries to the file, including punctuation, and then save: Please note that the file should contain 4 lines. The first 3 lines should contain the sentences shown above, including punctuation. The fourth line should be empty. You need the fourth line to test that your program properly ignores empty lines. 7. Now, edit the project's run properties to add "cosmic" (no quotation marks) in the "Arguments" category. Also, add (or select) "sentenceutils.SentenceUtilsTest" in the "Main Class" category. Then, click "OK". 8. Now, clean and build your project. If you have entered all of the template code correctly, the project should build successfully and no errors should be reported. If any errors are reported, fix them. The errors will be either in the source files or in the project properties. Clean and build again, and repeat until successful. 7. At this point, your NetBeans project hierarchy should look like this: Notice


that you can clearly see in the "dist" folder that the JAR file contains both the executable ".class" files and also the corresponding ".java" source files. 8. You are now ready to implement the required processing logic. Just follow the specific instruction in the sections below. Input File Format The input file to the program will be a text file. However, the file name may or may not include a ".txt" file extension, so do not test whether the name includes ".txt", and do not add ".txt" if it is not present. Just take in the command argument and use it as the file name just the way it is. There will be one sentence on each line. The sentences may include upper and lower case letters, numbers, punctuation marks, and special characters. There may be one or more empty lines at the end of the file, which your program should be able to ignore. The "cosmic" file you created in step 6 above is a sample input file. SentenceUtilsTest.java This file contains the test driver class. The template code already reads in the input file name as a command line argument. It also ignores empty input lines. Please note that this class contains a List of SentenceUtils objects called "slist". The template code reads each sentence and invokes the SentenceUtils constructor to create (instantiate) a SentenceUtils object for that sentence. It then adds the newly created object to the list. Your job here is to add the necessary Java statements to generate the output in the format shown in the sample format below. This code should include looping through the SentenceUtils objects in the list, and for each such object, invoking its "report()" method, which you will also write (see the next section, below). SentenceUtils.java This file contains the sentence utilities class. The template code already specifies the class members and implements the constructor. It also contains empty stubs for the methods that you will need to implement. The constructor already places the input sentence into the "sentence" variable (member). You must implement the "generateTokens()" method to chop up the


sentence into its tokens and to place these tokens into the String array "tokens". A "token" is any whitespace-separate character string, so you may use a Scanner on the sentence String to give you the tokens one-by-one. You must also implement the "generateShingles()" method to chop up the sentence into 2-character "shingles". A "shingle" is simply a String that contains two consecutive characters. They are called shingles because they must overlap, that is, the first character of the next shingle is the second character of the previous shingle. For example, consider the String "banana split". The shingles for this string are: 'ba' 'an' 'na' 'an' 'na' 'a ' ' s' 'sp' 'pl' 'li' 'it' Please note that this list include duplicates. It also includes the space character, which appears in the shingles 'a ' and ' s', For our purposes, you should include all whitespace, punctuation, special characters, and numbers in our shingles, exactly as they appear. Also, you should not convert upper case letters to lower case, or vice versa. Finally, you should also implement the "report()" method. This method should output to the console the following information, as shown on the sample output: (a) the full sentence (all on one line); (b) the individual tokens, numbered as shown, one to each line; and (c) all of the shingles on one line, separated by spaces, as shown. Output lines that are longer than your command window width will wrap to succeeding lines, as in the sample output below. Please note that whitespace in the shingles makes them look like they are not separated correctly, but if you count the characters, you should find that the output is correct. This phenomenon occurs at token boundaries, as in the example above. Please surround your shingles with single quotation marks, as in the example above and the sample output below. Please also note that the numbering of the sentences must be done in the test driver class, not in SentenceUtils, since a particular sentence has no way of knowing the order in which it appears in the "slist" list that is maintained by


SentenceUtilsTest. Output Format: Your program should present all output to the console (System.out). The output report should be in the following form: Please note that the shingle output will not appear line-wrapped as above in your NetBeans output pane. You should print them out all on one line, no matter how long that line may be. The line-wrapping above was achieved by cutting and pasting from the NetBeans output pane to a text editor. It is shown in this manner so you can easily check your program's operation against the "cosmic" file output by examining every one of the shingles. Program Testing If you have followed all steps in the NetBeans setup procedure above, you should be able to compile and run your program within NetBeans, using as input the "cosmic" file that you created in the project. It should produce the same output as shown above. Once you are satisfied with your program in NetBeans, use the NetBeans "Clean and Build" command to generate a fresh JAR file. Then, from the NetBeans "Files" tab, examine your JAR file to be sure it contains both .java source files. You will find the JAR file in the "dist" subfolder within your NetBeans project. Once you have confirmed that your source file is in the JAR file, get out of NetBeans and use your system's file manager to copy both the JAR file and the "cosmic" file to your desktop. Then, open a command window and navigate to your desktop and run your program using this command:


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.