I was given an assignment in which I have to:
A) Use an array list
and
B) From a set of data (that is in a text file) containing a runner's finishing time and their sex, output the times in order of Fastest Time, Fastest Male Time, and Fastest Female Time.
For example, the file will read something like:
6
48 F
52 M
43 F
49 F
50 M
57 F
Where the first line is the number of runners and the other lines are each runner's time and their sex (M for Male, F for Female)
then, the computer must print something like:
43 48 50
Note how the second-fastest female got the title of "fastest female" because the one that ran the race in 43 got the "fastest overall" title.
The most challenging part about this assignment for me is the fact that you have to deal with the time AND sex while sorting out which student is the fastest. I genuinely have no idea how to approach that problem.
So far what I have accomplished is That I have successfully read and transferred the data in the file and stored it as an ArrayList on the system. Here is the Arraylist Version:
public class RaceClient {
public static void main(String [] args) throws IOException {
Scanner inFile = new Scanner(new File("input.txt"));
ArrayList<String> times = new ArrayList<>();
ArrayList timesnum = new ArrayList();
while(inFile.hasNext()) {
times.add(inFile.nextLine());
}//end of while
times.remove(0);
int i=0;
while( i <times.length()) {
timesnum[i]= Integer.parseInt(times[i]);
}
System.out.println(times);
}//end of main
}//end of class
Any suggestions on what I should do or what I should import would be great