First some background:
The main method will drive your program by doing the following: •Create an array to hold all the individual golfers and par scores (type is Golfer[ ]). •Prompt the user for a data file containing the Par scores and the player names and score. The format of the input file should look like:
Par, 3, 4, 4, 3, 4, 3, 5, 3, 4
George, 3, 3, 4, 3, 4, 2, 3, 3, 4
Paul, 4, 5, 4, 3, 6, 3, 4, 3, 5
Ringo, 3, 3, 4, 3, 4, 2, 4, 3, 4
John, 4, 4, 4, 3, 4, 2, 5, 3, 4
This is what I have so far:
import java.io.File;
import java.io.IOException;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
boolean tryAgain;
do
{
Scanner console = new Scanner( System.in );
System.out.print( "Please enter a file name to read: " );
String inFile = console.next();
tryAgain = false;
try
{
File file = new File( inFile );
Scanner tokens = new Scanner( file );
int data[][];
String str = "";
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 10; j++)
{
int value = tokens.nextInt();
}
System.out.printf("\n");
}
tokens.close();
String people [] = str.split(",");
Golfer golfers = new Golfer(null, null);
}
catch (IOException e)
{
System.out.printf("Error opening file %s, %s\n", inFile, e);
tryAgain = true;
}
}
while (tryAgain);
}
I am unsure of how to properly use a nested for loop to pull the data and store it in an array since there are two data types. And... I guess any suggestions on how to store the information in my Golfer class couldn't hurt. I am a beginner so any complicated techniques should probably be avoided.
Any advice would be greatly appreciated. Thanks!
Golfer. Perhaps write a method to parse a single line into aGolfer.instanceofin a condition :)