Figure 7.8 contains an array of survey responses that is

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 */

 

Leave a Comment

Your email address will not be published. Required fields are marked *

GradeEssays.com
We are GradeEssays.com, the best college essay writing service. We offer educational and research assistance to assist our customers in managing their academic work. At GradeEssays.com, we promise quality and 100% original essays written from scratch.
Contact Us

Enjoy 24/7 customer support for any queries or concerns you have.

Phone: +1 213 3772458

Email: support@gradeessays.com

© 2024 - GradeEssays.com. All rights reserved.

WE HAVE A GIFT FOR YOU!

15% OFF 🎁

Get 15% OFF on your order with us

Scroll to Top