I'm a bit stuck on this, and it's the first time I am at a loss as to what direction to take. The problem: Write a program to process golf scores stored in a text file. Each line contains 5 values, par and the scores for 4 golfers. I need to determine a winner, and produce a table of the golfers scores.
What I have so far:
Obviously, this direction isn't working out.Code:
public class golfscores
public static void main (String args) throws IOException
int g1score=0, g2score=0, g3score=0, g4score=0, par=0;
Scanner fileScan, scoresScan;
fileScan = new Scanner (new File("scores.txt"));
scores = fileScan.nextLine();
System.out.println ("Par: " + fileScan.next());
scoresScan = new Scanner (scores);
System.out.println(" " + scoresScan.next());
I know I need useDelimiter() to seperate each golfers scores, and then parseInt() the value to change it from a String to an Int so I can add each value to my variables g1score, g2score etc, but I am not sure how to go about that. Do I need 5 different deliminators, one for par and one for each individual golfer's scores?
My table of data (text file without deliminators) looks something like:
4 5 3 4 4
5 8 4 5 5
Can anyone point me in the right direction? Do I need to use 5 nested while statements, and do a scan for each deliminator?