• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Formatter question(File)

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic