Question: You will use a 1 D integer array to keep track of the number of times each of the 1 2 8 characters appears in

You will use a 1D integer array to keep track of the number of times each of the 128 characters appears in the input file.Then, once the entire file has been read and each character has been accounted for, you will print (only from index 32 to 126 inclusive) to the output file in the following format:[character],[ascii value],[occurrences],[frequency]NO SPACE before or after the comma.character: is the character itself (e.g. A, r,).ascii value: is the decimal value of the character (e.g.65,114,).occurrences: number of times the character appears in the file.frequency: is a percentage computed by (occurrences)/(total number of characters in the file)*100How to read one character at a time from the input file?The first argument, args[0] will be the input file.Use StdIn.setFile(args[0]) to set the input file.Read characters while there are characters to be read from the file. StdIn.hasNextChar() returns true if there are characters to be read.To read one character use StdIn.readChar()How to keep track of the number of times a character appears in the input file?Use a 1D integer array (size 128) to keep track of the number of times each character appears in the input file.If you look at the ASCII table you will notice that:The first 32 characters (0 through 31) cannot be printed and ARE NOT of interest to this assignment.Character 32 through 126(inclusive) ARE the characters of interest to this assignment.Notice that each character has a decimal value. The decimal value (represents the character) is the value stored in the computer.The character A has decimal value 65.When you cast a char as an int, the value is the characters decimal value.The println() below will print 65 when the two lines of code are executed. Try it!char c ='A';System.out.println((int) c);Once a character is read from the file, use the character as the array index (cast the character as an integer).
e.If you read an A, index 65 is expected to be incremented. If, for example, you read 4, then index 52 is expected to be incremented. This way you will be able to keep track of the number of times each character appears in the file. How to write to the output file? The second argument, args[1] will be the output file. Use StdOut.setFile(args[1]) to set the output file. Then use StdOut.println() to write to the file. Once the entire file has been read. Print to the output file (only from index 32 to 126 inclusive) in the following format: [character],[ascii value],[occurrences],[frequency] NO SPACE before or after the comma.
Notes: Only modify the main method, no helper methods necessary. Keep track of the number of times the character appears for all characters in the file, but only print out char values of 32 to 126 inclusive to the output file.e.If you read an A, index 65 is expected to be incremented. If, for example, you read 4, then index 52 is expected to be incremented. This way you will be able to keep track of the number of times each character appears in the file. How to write to the output file? The second argument, args[1] will be the output file. Use StdOut.setFile(args[1]) to set the output file. Then use StdOut.println() to write to the file. Once the entire file has been read. Print to the output file (only from index 32 to 126 inclusive) in the following format: [character],[ascii value],[occurrences],[frequency] NO SPACE before or after the comma. Notes: Only modify the main method, no helper methods necessary. Keep track of the number of times the character appears for all characters in the file, but only print out char values of 32 to 126 inclusive to the output file.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!