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
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.
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.
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.