Hi,
Im new to java, mostly done networking in the past, im trying to create a program that will run a basic simulation of a number of heats for a 100m sprint. It mostly about the use of collections so nothing to complex but im completly lost.
I've created a number of runner objects and stored them in 2 arraylists called race and race2, I've also set the times to zero for each runner. What im trying to do right now is run through the objects in the arraylist and randomise the time for each runner within 9 to 10 secs in order to give a sort of realistic time for the race. Then I want to sort them by time first to last and pull the top 3 out of the arraylists and store them in another arraylist call winners. I've been thinking I have to use a loop and set the time with a setTime method for each object then sort them by time 1st to last but im completly lost and have basically started the whole thing again just with the objects stored in the arraylist.
Any help or suggestions would be very gratefully recieved
Thanks
This is my main class and runner class
import java.util.ArrayList;
import java.io.*;
public class RaceSim{
public static void main(String[] args){
Runner p1 = new Runner("Mark", "Brady", 00.00);
Runner p2 = new Runner("Karl", "Collins", 00.00);
Runner p3 = new Runner("Brian","Morgan", 00.00);
Runner p4 = new Runner("Stephen","Fryer", 00.00);
Runner p5 = new Runner("Stephen","Taylor", 00.00);
Runner p6 = new Runner("Gavin","Burke", 00.00);
Runner p7 = new Runner("John","McGlynn", 00.00);
Runner p8 = newRunner("Robert","Banks", 00.00);
ArrayList<Runner> race = new ArrayList<Runner>();
race.add(p1);
race.add(p2);
race.add(p3);
race.add(p4);
race.add(p5);
race.add(p6);
race.add(p7);
race.add(p8);
Runner p9 = new Runner("Aaron", "McNutt", 00.00);
Runner p10 = new Runner("Kevin", "McCafferty", 00.00);
Runner p11 = new Runner("Harold","McCarron", 00.00);
Runner p12 = new Runner("Declan","McCormack", 00.00);
Runner p13 = new Runner("Micheal","McGoldrick", 00.00);
Runner p14 = new Runner("David","Hegerty", 00.00);
Runner p15 = new Runner("Ryan","Lynce", 00.00);
Runner p16 = newRunner("Conal","Murphy", 00.00);
ArrayList<Runner> race2 = new ArrayList<Runner>();
race2.add(p9);
race2.add(p10);
race2.add(p11);
race2.add(p12);
race2.add(p13);
race2.add(p14);
race2.add(p15);
race2.add(p16);
System.out.println(race + "\n");
System.out.println(race2 + "\n");
}
}
public class Runner {
private String fName;
private String sName;
private double time;
public Runner(){
}
public Runner(String fName, String sName, double time){
this.fName = fName;
this.sName = sName;
this.time = time;
}
public double getTime(double time){
return time;
}
public void setTime(double time){
this.time = time;
}
}