diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index 4b336ba2..6fd4829e 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -27,6 +27,12 @@ public class App race.addBoat(new Boat(boatNames.get(i))); } + race.addLeg(new Leg(035, 100, "Start")); + race.addLeg(new Leg(010, 300, "Marker 1")); + race.addLeg(new Leg(350, 400, "Leeward Gate")); + race.addLeg(new Leg(010, 400, "Windward Gate")); + race.addLeg(new Leg(010, 400, "Leeward Gate")); + return race; } @@ -43,11 +49,11 @@ public class App } if (race != null){ - race.displayStartingBoats(); - - System.out.println(""); + race.startRace(); race.displayFinishingOrder(); + + } else{ System.out.println("e"); diff --git a/src/main/java/seng302/Leg.java b/src/main/java/seng302/Leg.java index 9db54109..862725a2 100644 --- a/src/main/java/seng302/Leg.java +++ b/src/main/java/seng302/Leg.java @@ -3,44 +3,98 @@ package seng302; public class Leg { private int heading; private int distance; - private String startLabel; private boolean isFinishingLeg; + private Marker startingMarker; - public Leg(int heading, int distance, String label){ + /* + Create a new leg + + @param heading, the magnetic heading of this leg + @param distance, the total distance of this leg in meters + @param marker, the marker this leg starts on + */ + public Leg(int heading, int distance, Marker marker){ this.heading = heading; this.distance = distance; - this.startLabel = label; + this.startingMarker = marker; this.isFinishingLeg = false; } + /* + Create a new leg + + @param heading, the magnetic heading of this leg + @param distance, the total distance of this leg in meters + @param markerName, the name of the marker this leg starts on + */ + public Leg(int heading, int distance, String markerName){ + this.heading = heading; + this.distance = distance; + this.startingMarker = new Marker(markerName); + this.isFinishingLeg = false; + } + + /* + Set the heading for this leg + */ public void setHeading(int heading){ this.heading = heading; } + /* + Get the heading of this leg + */ public int getHeading(){ return this.heading; } + /* + Set the distance of this leg in meters + */ public void setDistance(int distance){ this.distance = distance; } + /* + Get the total distance of this leg in meters + */ public int getDistance(){ return this.distance; } - public void setLabel(String label){ - this.startLabel = label; + /* + Set the marker this leg starts on + */ + public void setMarker(Marker marker){ + this.startingMarker = marker; } - public String getLabel(){ - return this.startLabel; + /* + Returns the marker this leg started on + */ + public Marker getMarker(){ + return this.startingMarker; } + /* + Returns the name of the marker this leg started on + */ + public String getMarkerLabel(){ + return this.startingMarker.getName(); + } + + /* + Specify whether or not the race finishes on this leg + + @param isFinishingLeg whether or not the race finishes on this leg + */ public void setFinishingLeg(boolean isFinishingLeg){ this.isFinishingLeg = isFinishingLeg; } + /* + @returns true if this the race finishes after this leg + */ public boolean getIsFinishingLeg(){ return this.isFinishingLeg; } diff --git a/src/main/java/seng302/Marker.java b/src/main/java/seng302/Marker.java new file mode 100644 index 00000000..2bed2dc0 --- /dev/null +++ b/src/main/java/seng302/Marker.java @@ -0,0 +1,17 @@ +package seng302; + +class Marker{ + private String name; + + public Marker(String name){ + this.name = name; + } + + public void setName(String name){ + this.name = name; + } + + public String getName(){ + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/seng302/Race.java b/src/main/java/seng302/Race.java index 8616dd93..be4ebacc 100644 --- a/src/main/java/seng302/Race.java +++ b/src/main/java/seng302/Race.java @@ -25,6 +25,19 @@ public class Race { numberOfBoats += 1; } + /* + Returns a list of boats in a random order + + @returns a list of boats + */ + public Boat[] getShuffledBoats(){ + // Shuffle the list of boats + long seed = System.nanoTime(); + Collections.shuffle(this.boats, new Random(seed)); + + return boats.toArray(new Boat[boats.size()]); + } + /* Returns a list of boats in the order that they finished the race (position 0 is first place) @@ -32,11 +45,7 @@ public class Race { @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()]); + return getShuffledBoats(); } /* @@ -74,24 +83,42 @@ public class Race { /* Prints the list of boats competing in the race */ - public void displayStartingBoats(){ + private void displayStartingBoats(){ int numberOfBoats = this.getNumberOfBoats(); Boat[] boats = this.getBoats(); - System.out.println("--- Competing Boats ---"); + System.out.println("--- Starting Boats ---"); for (int i = 0; i < numberOfBoats; i++) { System.out.println(boats[i].getTeamName()); } } + /* + Adds a leg to the race + + @param leg, the leg to add to the race + */ public void addLeg(Leg leg){ this.legs.add(leg); } - public void printLegs(){ + /* + Start the race and print each marker with the order + in which the boats passed that marker + */ + public void startRace(){ for (Leg leg : this.legs.toArray(new Leg[legs.size()])){ - System.out.println(leg.getLabel()); - } + Boat[] boats = this.getShuffledBoats(); + + System.out.println("--- " + leg.getMarkerLabel() + " ---"); + + // Print the order in which the boats passed the marker + for (int i = 0; i < this.getNumberOfBoats(); i++) { + System.out.println("#" + Integer.toString(i+1) + " - " + boats[i].getTeamName()); + } + + System.out.println(""); + } } } \ No newline at end of file