I am a beginner level java programmer. I have three class files:
AddressBook.class
BanffMarathonRunnerDemo.class
BanffMarathonRunner.class
BanffMarathonRunner extends the AddressBook class. And BanffMarathonRunnerDemo creates the array and calls BanffMarathonRunner.
I have made numerous attempts to sort my array by Time in BanffMarathonRunner. But can not seem to figure it out. Can someone show me how this is done?
public class BanffMarathonRunnerDemo {
public static void main(String[] args) {
BanffMarathonRunner[] runners = new BanffMarathonRunner[15];
runners[0] = new BanffMarathonRunner("Elena", "Brandon", 341, 1);
runners[1] = new BanffMarathonRunner("Thomas", "Molson", 273, 2);
runners[2] = new BanffMarathonRunner("Hamilton", "Winn", 278, 5);
runners[3] = new BanffMarathonRunner("Suzie", "Sarandin", 329, 7);
BanffMarathonRunner firstplace = BanffMarathonRunner.getFastestRunner(runners);
printWinner(firstplace);
} // End of main
static void printWinner(BanffMarathonRunner runner) {
System.out.println("Banff Marathon Winner");
System.out.println(runner.getFirstName() + " " + runner.getLastName());
System.out.println(runner.getTime());
}
} // End of class BanffMarathonRunnerDemo
public class BanffMarathonRunner extends AddressBook {
private int time;
private int years;
public BanffMarathonRunner(String firstName, String lastName, int min, int yr) {
super(firstName);
super.setLastName(lastName);
this.time = min;
this.years = yr;}
public int getTime() {return this.time;}
public int getYears() {return this.years;}
public void setTime(int time) {this.time = time;}
public void setYears(int years) {this.years = years;}
public static BanffMarathonRunner getFastestRunner(BanffMarathonRunner[] runners) {
BanffMarathonRunner fastestRunner = runners[0];
// SORT ARRAY HERE BY TIME
return fastestRunner;
}
} // End of BanffMarathonRunner