From 33994bd3e4755566e61e70ce808d19b05f51d3eb Mon Sep 17 00:00:00 2001 From: Michael Rausch Date: Fri, 3 Mar 2017 18:06:51 +1300 Subject: [PATCH] Implemented 'Race' class - Boats can be added to a race - calling getFinishedBoats() will return a list of boats in the order that they finished --- src/main/java/seng302/Boat.java | 1 + src/main/java/seng302/Race.java | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/seng302/Race.java diff --git a/src/main/java/seng302/Boat.java b/src/main/java/seng302/Boat.java index 670aa04b..3361e965 100644 --- a/src/main/java/seng302/Boat.java +++ b/src/main/java/seng302/Boat.java @@ -9,6 +9,7 @@ public class Boat { // The name of the team, this is also the name of the boat private String teamName = null; + private boolean finishedRace = false; public Boat(String teamName) { this.teamName = teamName; diff --git a/src/main/java/seng302/Race.java b/src/main/java/seng302/Race.java new file mode 100644 index 00000000..06fb7901 --- /dev/null +++ b/src/main/java/seng302/Race.java @@ -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 boats; + + public Race(){ + boats = new ArrayList(); + } + + /* + 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()]); + } +} \ No newline at end of file