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.
For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...
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,...
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...
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...
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 question: Write a program that reads in data from a text file named in.txt. Compute the sum of all the valid integers in the input file. Likewise, compute the sum of all the valid doubles in the input file. Write the former to an output file called int_total.txt, and write the latter to an output file called double_total.txt. B) Write a program that converts the Java source code from the next-line brace style to the end-of-line brace style. For...
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...
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...
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...
In java
Assignment Modify the code Binary File IO Example Code. The code reads and prints information about a BMP file. Modify the code so that it also prints the resolution of the BMP file (both width and height) and the number of bits per pixel. Do not use any Java library or third-party library code that reads BMP files. You must read the file using simple Java code and extract the information, similar to the code in the example....
java find and replace code pls help me We write code that can find and replace in a given text file. The code you write should take the parameters as command line arguments: java FindReplace -i <input file> -f "<find-string>" -r "<replace-string> -o <output file> *question mark(?) can be used instead of any character. "?al" string an be sal ,kal,val *In addition, a certain set of characters can be given in brackets.( "kng[a,b,f,d,s]ne" string an be kngane,hngbne,kangfne,kangdne,kangsne So, all you...