Could I get some help with this assignment
In this assignment, you'll write a program which reads a text file, and prints a histogram of its word sizes. So, for example, the historgram should show the number of words of length 1, of length 2, etc., up to the number of words of length n, where n is some constant defined in your program.
To obtain text files that are suitably long, you could try Project Gutenberg, a site containing thousands of free books available in several different formats (for this assignment, you're interested in files in plain text format).
For your convenience, a mirrored local copy of a book is here. http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html
Attach a Scanner to a File object associated with the file, and read the file, noting the length of each word. Hint: to tell your Scanner to use any non-word characters as a delimiter, you could do something like:
Scanner fin = new Scanner(new File(filename));
fin.useDelimiter("\\W+");
(It's not necessary for this assignment, but if you're curious, other possibilities for patterns may be found in thejava.util.regex.Pattern API page.)
Once you've counted the number of words of each size, the program should print a histogram. When I run my program on the Autobiography of Benjamin Franklin, it produces the following histogram:
Len Count 1 4661 ******************************** 2 13855 ************************************************************************************************ 3 14417 **************************************************************************************************** 4 11456 ******************************************************************************* 5 7323 ************************************************** 6 5344 ************************************* 7 4912 ********************************** 8 3132 ********************* 9 2671 ****************** 10 1622 *********** 11 842 ***** 12 503 *** 13 226 * 14 61 >=15 26
Do not hard code the name of the file to read. This, instead should be determined at runtime. Either prompt the user for the name of the file (or pass it as a command-line argument). If there is an error opening the file, the program should print an error message and exit. This should be done by handling FileNotFoundException.
We don't know in advance how large the file will be, or the count of words (so, for example, we won't know how long the longest line of '*'s will be), and we don't want the histogram to have lines which wrap. For this reason, the number of words that the '*' represents should be determined only after you've counted all of the words in the file.
Good programming style will play a part in your final grade for the assignment. Please be sure to break up the code into separate functions, and document your code.
what to submit
Send your .java file. It is not necessary to send your practice text files.
main.java
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class main
{
/**
* @param args the command line
arguments
*/
public static void main(String[] args)
{
try
{
translateNumbersInFile("translate.txt");
}
catch(FileNotFoundException ex)
{
System.err.println("File cannot be found");
}
}//main
/**
* This method is used to take a file and
print it into text format.
*
* @param filename
* @throws FileNotFoundException
*/
public static void translateNumbersInFile(String
filename) throws
FileNotFoundException
{
//variables needed for
method
Scanner
fin
= new Scanner(new File(filename));
fin.useDelimiter("
|\n");
NumberTranslator translate =
new NumberTranslator();
//use while loop to read all
numbers
while(fin.hasNext())
{
String s = fin.next();
if (s.length() > 0)
{
System.out.println(translate.translate(new Integer(s)));
}
}
fin.close();
}//translateNumbersInFile
}//end
NumberTranslator.java
public class NumberTranslator
{
public String translate(int number)
{
//find the length of the
number
Integer
numValueAsInteger = number;
int numberPlace =
numValueAsInteger.toString().length();
//declare variable used
for holding the number being processed
int currentValue =
0;
//the holder value for
the words describing the int value
String numberToString =
"";
//find value in all
places. ex: ones, tens, hundreds.
for(int i = 0;i<
numberPlace;i++)
{
if (i > 0)
{
numberToString += " ";
}
//these hold the two types of numbers handled
currentValue =
Integer.parseInt(numValueAsInteger.toString().charAt(i) +
"");
switch(currentValue)
{
case 0:
numberToString += "zero";
break;
case 1:
numberToString += "one";
break;
case 2:
numberToString += "two";
break;
case 3:
numberToString += "three";
break;
case 4:
numberToString += "four";
break;
case 5:
numberToString += "five";
break;
case 6:
numberToString += "six";
break;
case 7:
numberToString += "seven";
break;
case 8:
numberToString += "eight";
break;
case 9:
numberToString += "nine";
break;
}//switch
}//for
return number +": "+
numberToString;
}
}
Could I get some help with this assignment In this assignment, you'll write a program which...
//I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...
Description: Overview: You will write a program (says wordcountfreq.c) to find out the number of words and how many times each word appears (i.e., the frequency) in multiple text files. Specifically, the program will first determine the number of files to be processed. Then, the program will createmultiple threads where each thread is responsible for one file to count the number of words appeared in the file and report the number of time each word appears in a global linked-list....
Could you guys write an efficient java program to implement BST. Your java program should read words and its corresponding French and store it in a BST. Then read every English word and print its corresponding French by searching in BST. Assume your java program is in xxxxx5.java file (5th java project), where xxxxx is the first 5 characters of your last name. To compile: javac xxxxx5.java To execute: java xxxxx5 < any data file name Your main method should...
C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...
I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt Project#3 is an extension of the concepts and tasks of Lab#3. You will again read the dictionary file and resize the array as needed to store the words. Project#3 will require you to update a frequency counter of word lengths every time a word is read from the dictionary into the wordList. When your program is finished this histogram array will contain the following:...
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...
Python program This assignment requires you to write a single large program. I have broken it into two parts below as a suggestion for how to approach writing the code. Please turn in one program file. Sentiment Analysis is a Big Data problem which seeks to determine the general attitude of a writer given some text they have written. For instance, we would like to have a program that could look at the text "The film was a breath of...
Hi, I need help with my comp sci assignment. The parameters are listed below, but I am having trouble generating the number of occurrences of each word. Please use a standard library. Read in the clean text you generated in part 2 (start a new cpp file). Create a list of all the unique words found in the entire text file (use cleanedTextTest.txt for testing). Your list should be in the form of an array of structs, where each struct...
Python 3.7 Coding assignment This Program should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time. Ask a user to enter the name of a text file....
Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...