I have a class called Runner which looks like this:
public class Runner
{
private static int nextNumber= 1;
private int number;
private String name;
private String ageGroup;
private int time;
public Runner()
{
super();
this.name = "";
this.ageGroup = "standard";
this.time = 0;
this.number = nextNumber++;
}
It also includes standard getter and setter methods. In another class I am trying to write a method that reads in data from a text file and assigns the data to a list. My method currently looks like this:
public void readInRunners()
{
String pathname = OUFileChooser.getFilename();
File aFile = new File(pathname);
Scanner bufferedScanner = null;
List<Runner> runners = new ArrayList<>();
try
{
String name;
int age;
String ageGroup;
Scanner lineScanner;
String currentLine;
bufferedScanner = new Scanner(new BufferedReader(new FileReader(aFile)));
while (bufferedScanner.hasNextLine())
{
currentLine = bufferedScanner.nextLine();
lineScanner = new Scanner(currentLine);
lineScanner.useDelimiter(",");
name = lineScanner.next();
age = lineScanner.nextInt();
if(age < 18)
{
ageGroup = ("junior");
}
else if(age >= 55)
{
ageGroup = ("senior");
}
else if(age >= 18 && age < 55)
{
ageGroup = ("standard");
}
runners.add(new Runner(name, ageGroup));
}
}
catch (Exception anException)
{
System.out.println("Error: " + anException);
}
finally
{
try
{
bufferedScanner.close();
}
catch (Exception anException)
{
System.out.println("Error: " + anException);
}
}
I am getting an error on this line:
runners.add(new Runner(name, ageGroup));
I know that is isn't compiling because of the incompatible argument but I'm unsure how to phrase this otherwise.
Any advice would be greatly appreciated.