Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formatter question(File)

 
Steven Alvarez
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I DON'T WANT SOMEONE TO WRITE THIS PROGRAM, I just need help.

The question goes as follows:


(Student Poll) 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 in Fig. 7.8 to read the survey responses from numbers.txt. The responses should be read from the file by using a Scanner. Method nextInt 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".


The part I need help in is understanding this part:

Use a Formatter to create a file called numbers.txt. Each integer should be written using method format.


Can I use the FileWriter class? Or do I have to use "Formatter" to write the file? If so, can you give an example of how to do so?

Also what does this part mean?

Each integer should be written using method format.


Thanks!!
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven Alvarez wrote:Can I use the FileWriter class?

You can, but then you would do the hard work.

Or do I have to use "Formatter" to write the file? If so, can you give an example of how to do so?

You need to use Formatter (I think they refer to java.util.Formatter). After all, that's the requirement.

Also what does this part mean?

Each integer should be written using method format.

I think if you click on that java.util.Formatter link and look through that API page you will get what they are asking of you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic