Question

For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

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 of the sample output below, which corresponds to the sample input file that is provided to you.
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.

You should use the cats.txtPreview the document for development testing to make sure your program works correctly. If, for some reason the file is not compatible with your system, you can just create the file with the following contents:

cats.png

If you create the file on your own, please be sure to create the file as a text file, not a "rich-text" file (".rtf") file.

Also, please note that the file contains an empty line after the third line. This is intentional. Your program should successfully ignore empty lines like this.

SentenceUtilsTest.java
This file contains the test driver class. The template code already reads in the input file name as a command line argument and instantiates a Scanner to read the file. This is the template for this source file:

3330-prog2-template-driver.png

Your job for this Java class is to create the file by typing in the code above, and then add the necessary Java statements to do the following:

use the scanner to read read the file and invoke the SentenceUtils constructor to create (instantiate) a SentenceUtils object for each sentence; you must be sure to ignore empty lines as you do this;
add the newly created object to the List of SentenceUtils objects called "slist" that is already declared and created as a class variable for you in the template; and
loop through the SentenceUtils objects in the list, and for each such object, output a sentence heading showing the sentence number, and invoke its "report()" instance method, which you will also write (see the next section, below).
Please note that the sentence numbering must be done in this 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 this SentenceUtilsTest class. The number of a sentence should be reported as the zero-based index of the sentence's entry in slist.

SentenceUtils.java
This file contains the sentence utilities class. The template code already specifies the class members and implements the constructor. The constructor already places the input sentence into the "sentence" variable (member). The template also contains empty stubs for the methods that you will need to implement. This is the template for this source file:

3330-prog2-template-model.png

Your job for this Java class is to create the file by typing in the code above, and then add the necessary Java statements to do the following:

(1) You must implement the "generateTokens()" method to chop up a 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.

(2) 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.

(3) 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, ten (10) on each line, separated by spaces, as shown in the sample output below. Each shingle should be surrounded by single quotation marks to make it clear when shingles contain spaces, as in the example above and the sample output below.

Output Format:
Your program should present all output to the console (System.out). The output report should be in the following format:

3330-prog2-sample.png

Required File Header
Your Java source files must contain a file header in the following format so we know it is your code:

header-3330-19sp.png

Please note that this assignment has 2 required source files and there is a 20-point deduction if either file header is missing or incomplete.

If you are teaming, the file headers must name both teammates.

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java...

    4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...

  • Capitalization JAVA In this program, you will read a file line-by-line. For each line of data...

    Capitalization JAVA In this program, you will read a file line-by-line. For each line of data (a string), you will process the words (or tokens) of that line one at a time. Your program will capitalize each word and print them to the screen separated by a single space. You will then print a single linefeed (i.e., newline character) after processing each line – thus your program will maintain the same line breaks as the input file. Your program should...

  • Regular Expression processor in Java Overview: Create a Java program that will accept a regular expression...

    Regular Expression processor in Java Overview: Create a Java program that will accept a regular expression and a filename for a text file. The program will process the file, looking at every line to find matches for the regular expression and display them. Regular Expression Format The following operators are required to be accepted: + - one or more of the following character (no groups) * - zero or more of the following character (no groups) [] – no negation,...

  • Homework description::::: Write JAVA program with following description. Sample output with code will be helful... A...

    Homework description::::: Write JAVA program with following description. Sample output with code will be helful... A compiler must examine tokens in a program and decide whether they are reserved words in the Java language, or identifiers defined by the user. Design a program that reads a Java program and makes a list of all the identifiers along with the number of occurrences of each identifier in the source code. To do this, you should make use of a dictionary. The...

  • Need help with java programming. Here is what I need to do: Write a Java program...

    Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1.     The input and variable value file are both text files that will be specified in...

  • JAVA Write a program that prompts the user to enter a file name, then opens the...

    JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...

  • The objectives of this assignment are to: Further enhance your knowledge and skill in Java. Gain...

    The objectives of this assignment are to: Further enhance your knowledge and skill in Java. Gain an understanding and experience with stacks. Gain further experience using generics. Continue to practice good programming techniques. Create a stack class named MyStack that stores generics with the methods shown below. Write a test program that thoroughly tests your stack implementation. void push(E item) push item onto top of stack E peek() return item on top of stack E pop() return item on top...

  • Please Do it In Java: Objectives: To Java programming language To understand the lexical analysis phase...

    Please Do it In Java: Objectives: To Java programming language To understand the lexical analysis phase of program compilation Assignment: The first phase of compilation is called scanning or lexical analysis. This phase interprets the input program as a sequence of characters and produces a sequence of tokens, which will be used by the parser. Write a Java, program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described...

  • Write a program that will check a Java file for syntax errors. The program will ask...

    Write a program that will check a Java file for syntax errors. The program will ask for an input-file name and output-file name and will then copy all the code from the Java input file to the Java output file, but with the following changes: 1. Any syntax error found in the Java input file will be corrected: a. Missing semicolon b. Missing compound statements (curly braces) c. All comments have to start with // and end with a period....

  • In this lab you will write a spell check program. The program has two input files:...

    In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT