• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Writing to a text file

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would i complete the fileCreate method to write to a text file called "Results.txt" with this output?
819283761,15,100.0,30,A
834987341,9,60.0,18,D
899991828,13,86.66666666666667,26,B
888181818,9,60.0,18,D
892823736,6,40.0,12,F



 
Saloon Keeper
Posts: 10930
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alex Breault wrote:How would i complete the fileCreate method to write to a text file called "Results.txt" with this output?
819283761,15,100.0,30,A
834987341,9,60.0,18,D


I suggest looking in the Javadoc in the java.io package for appropriate classes to use. Specifically, character oriented classes and not byte oriented classes. And, of course, you should be looking for a class that supports output and not input. You may also want to keep an eye out for classes that buffer their data, not absolutely necessary, but more efficient.

There's also a lot of I/O tutorials available online.

Show us what you've come up with and let us know about any specific issues you're having.
 
Alex Breault
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This is the method now but it does not save all info into the text file, just the last students
 
Ranch Hand
Posts: 385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because each time you call fileCreate(), you are creating a new file, so anything you wrote to the file the previous time you called fileCreate(), gets overwritten.

BTW, you might also want to check getLetterGrade(), some of your students might be very angry, after all, if they scored 89.91%, they would rightly expect to be awarded a B grade, and not a F grade.
 
Carey Brown
Saloon Keeper
Posts: 10930
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would modify your fileCreate() to take a PrintWriter object. Actually, a better name for the method would be something like "fileWrite()". Then outside of your main loop, open up the PrintWriter, and inside your loop call fileWrite(). And don't forget to call close() when your loop completes.
 
Marshal
Posts: 79966
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For a simple text file I would use a Formatter. Get rid of things like DecimalFormat; look on that as legacy code.
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic