I need to create multiple "runner" objects each with three variables. The variables should be name, runner id, and amount raised. I have to read in two text files to get the information for these. One text files contains the runner id and runner name. The other text file contains the runner id and donation amount. I created a "driver" class to read in the files and pass the info to a constructor in a "runner" class to create the runner object. I used a string tokenizer to read in the individual parts from the files. I just don't know how to take those individual parts of the arrays and pass them to the correct methods to set the variables for the object. This is the code I have for the driver class. The lines with System.out.prin tln("") are just so I could see the contents of the arrays.
Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.ArrayList;
public class Driver {
public static void main(String[] args) throws FileNotFoundException{
ArrayList<String> data = new ArrayList<String>();
ArrayList<String> donations = new ArrayList<String>();
Scanner scanner1 = new Scanner(new File("data.txt"));
while (scanner1.hasNextLine()) {
String str1 = scanner1.nextLine().trim();
String[] tokens1 = str1.split(",");
for (String s : tokens1){
data.add(s);
}
}
System.out.println(data);
scanner1.close();
Scanner scanner2 = new Scanner(new File("donations.txt"));
while (scanner2.hasNextLine()){
String str2 = scanner2.nextLine().trim();
String[] tokens2 = str2.split(",");
for (String t : tokens2){
donations.add(t);
}
}
System.out.println(donations);
scanner2.close();
}
}