Thanks for posting the question, we are glad to help you .Here is the complete code in Java. Below is the output i generated in my system. You may need to change the below two paths in your system
private static final String inputFilePath = "F:\\numbers.txt"; private static final String outputFilePath = "F:\\output.txt";
____________________________________________________________________________________________________
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Formatter;
public class Ratings {
private static final String inputFilePath = "F:\\numbers.txt";
private static final String outputFilePath = "F:\\output.txt";
private static java.util.Scanner console;
public static void main(String[] args) {
int[][] ratingCount = new int[5][1];
try {
console = new java.util.Scanner(new File(inputFilePath));
while (console.hasNextLine()) {
String line = console.nextLine();
String[] ratings = line.split("\\s+");
for (String rating : ratings) {
if (rating.trim().length() == 0)
continue;
int rate = Integer.parseInt(rating);
if (rate == 1)
ratingCount[0][0] = 1 + ratingCount[0][0];
else if (rate == 2)
ratingCount[1][0] = 1 + ratingCount[1][0];
else if (rate == 3)
ratingCount[2][0] = 1 + ratingCount[2][0];
else if (rate == 4)
ratingCount[3][0] = 1 + ratingCount[3][0];
else if (rate == 5)
ratingCount[4][0] = 1 + ratingCount[4][0];
}
}
console.close();
} catch (FileNotFoundException fne) {
}
writeToFile(ratingCount);
}
public static void writeToFile(int[][] ratingCount) {
Formatter output = null;
try {
output = new Formatter(outputFilePath);
output.format("%-10s%-10s\r\n", "Rating", "Frequency");
for (int index = 0; index < ratingCount.length; index++) {
output.format("%-12d%-12d\r\n", index + 1, ratingCount[index][0]);
}
output.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
output.close();
}
}
}
___________________________________________________________________________________________________

Thank you !
In JAVA Twenty students were asked to rate on a scale of 1 to 5 the...
JAVA (Student Poll) Figure 7.8 contains an array of survey responses that’s hard coded into the program. Suppose we wish to process survey results that are stored in a file. This exercise requires two separate programs. First, create an application that prompts the user for survey responses and outputs each response to a file. Use a Formatter to create a file called numbers.txt. Each integer should be written using method format. Then modify the program in Fig. 7.8 to read...
Java : Please help me correct my code: create a single class (Program11.java) with a main method and some auxiliary methods to input a 2-D array from a disk file, input some “transactions” to change the 2-D array and output the changed 2-D array to another file. Your main method will be minimal (see below). Most of the work will go on in your methods. In main, declare (but do not instantiate) 2-D array. Then call the three methods. The...
JAVA Which of these statements does not match by using exception action in Java? 1. Exception action makes it possible for the calling method to handle errors in called methods. 2. Exception action simplifies programming since incorrect reporting and handling can be located in catch blocks separately from the rest of the code. 3. Exception action increases the performance of programs. 4. Java separates exception action from common processes. Why create instances of File Class? - several alternatives...
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...
Write a Java program in Eclipse that reads from a file, does some clean up, and then writes the “cleaned” data to an output file. Create a class called FoodItem. This class should have the following: A field for the item’s description. A field for the item’s price. A field for the item’s expiration date. A constructor to initialize the item’s fields to specified values. Getters (Accessors) for each field. This class should implement the Comparable interface so that food...
Please write a java program with a input file "jabberwock.txt", and output the "output.txt" with following requirement. You and your partner will be writing a simple Java program that implements some basic file I/O operations. You can use this code as the basis for some of your next project. FIRST: Write code that prompts the user for the name of a text file, opens that file if it exists and reads the file one line at a time printing each...
Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written to a file. Each line of the input file will contain the student name (a single String with no spaces), the number of semester hours earned (an integer), the total quality points earned (a double). The following shows part of a typical...
(Java) Rewrite the following exercise below to read inputs from a file and write the output of your program in a text file. Ask the user to enter the input filename. Use try-catch when reading the file. Ask the user to enter a text file name to write the output in it. You may use the try-with-resources syntax. An example to get an idea but you need to have your own design: try ( // Create input files Scanner input...
*Java*
You will write a program to do the following: 1. Read an input file with a single line of text. Create a method named load_data. 2. Determine the frequency distribution of every symbol in the line of text. Create a method named 3. Construct the Huffman tree. 4. Create a mapping between every symbol and its corresponding Huffman code. 5. Encode the line of text using the corresponding code for every symbol. 6. Display the results on the screen....
In Java, Implement a class MyArray as defined below, to store an array of integers (int). Many of its methods will be implemented using the principle of recursion. Users can create an object by default, in which case, the array should contain enough space to store 10 integer values. Obviously, the user can specify the size of the array s/he requires. Users may choose the third way of creating an object of type MyArray by making a copy of another...