Implemented 'Race' class

- Boats can be added to a race
- calling getFinishedBoats() will return a list of boats in the order that they finished
This commit is contained in:
Michael Rausch
2017-03-03 18:06:51 +13:00
parent 45eec5a288
commit 33994bd3e4
2 changed files with 38 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
package seng302;
import java.util.ArrayList;
import java.util.Random;
import java.util.Collections;
import java.util.List;
public class Race {
private ArrayList<Boat> boats;
public Race(){
boats = new ArrayList<Boat>();
}
/*
Add a boat to the race
@param boat the boat to add
*/
public void addBoat(Boat boat){
boats.add(boat);
}
/*
Returns a list of boats in the order that they
finished the race (0 is first)
@returns a list of boats
*/
public Boat[] getFinishedBoats(){
// Shuffle the list of boats
long seed = System.nanoTime();
Collections.shuffle(this.boats, new Random(seed));
return boats.toArray(new Boat[boats.size()]);
}
}