Figure 7.8 contains an array of survey responses that is 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 of Fig. 7.8 to read the survey responses from numbers.txt. The responses should be read from the file by using a Scanner. MethodnextInt should be used to input one integer at a time from the file. The program should continue to read responses until it reaches the end of file. The results should be output to the text file output.txt.
Example output for the two applications is shown below:
/* Output:
Enter integer result (1 – 10), -1 to quit: 3
Enter integer result (1 – 10), -1 to quit: 6
Enter integer result (1 – 10), -1 to quit: 2
Enter integer result (1 – 10), -1 to quit: 8
Enter integer result (1 – 10), -1 to quit: 4
Enter integer result (1 – 10), -1 to quit: 8
Enter integer result (1 – 10), -1 to quit: 4
Enter integer result (1 – 10), -1 to quit: 5
Enter integer result (1 – 10), -1 to quit: 7
Enter integer result (1 – 10), -1 to quit: 8
Enter integer result (1 – 10), -1 to quit: 9
Enter integer result (1 – 10), -1 to quit: -1
numbers.txt:
3 6 2 8 4 8 4 5 7 8 9 */
/* output.txt:
Rating Frequency
1 0
2 1
3 1
4 2
5 1
6 1
7 1
8 3
9 1
10 0 */