Display the order the boats finished in

- Added a function in the App class to display the order in which the boats finished the race

 #implement
This commit is contained in:
Michael Rausch
2017-03-03 18:39:15 +13:00
parent 4b2141190d
commit 6702d24fd5
2 changed files with 37 additions and 3 deletions
+24 -1
View File
@@ -1,9 +1,32 @@
package seng302; package seng302;
import java.util.ArrayList;
public class App public class App
{ {
/*
Displays the order in which the boats finished
@param race The current race
*/
public static void displayFinishingOrder(Race race){
int numberOfBoats = race.getNumberOfBoats();
Boat[] boats = race.getFinishedBoats();
System.out.println("--- Finishing Order ---");
for (int i = 0; i < numberOfBoats; i++) {
System.out.println("#" + Integer.toString(i+1) + " - " + boats[i].getTeamName());
}
}
public static void main( String[] args ) public static void main( String[] args )
{ {
System.out.println(""); Race race = new Race();
displayFinishingOrder(race);
} }
} }
+13 -2
View File
@@ -8,6 +8,7 @@ import java.util.List;
public class Race { public class Race {
private ArrayList<Boat> boats; private ArrayList<Boat> boats;
private int numberOfBoats = 0;
public Race(){ public Race(){
boats = new ArrayList<Boat>(); boats = new ArrayList<Boat>();
@@ -15,15 +16,16 @@ public class Race {
/* /*
Add a boat to the race Add a boat to the race
@param boat the boat to add @param boat, the boat to add
*/ */
public void addBoat(Boat boat){ public void addBoat(Boat boat){
boats.add(boat); boats.add(boat);
numberOfBoats += 1;
} }
/* /*
Returns a list of boats in the order that they Returns a list of boats in the order that they
finished the race (0 is first) finished the race (position 0 is first)
@returns a list of boats @returns a list of boats
*/ */
@@ -34,4 +36,13 @@ public class Race {
return boats.toArray(new Boat[boats.size()]); return boats.toArray(new Boat[boats.size()]);
} }
/*
Returns the number of boats in the race
@returns the number of boats in the race
*/
public int getNumberOfBoats(){
return numberOfBoats;
}
} }