From 5492ace1a3de4451bc801062eb052ef592e2bb7e Mon Sep 17 00:00:00 2001 From: Michael Rausch Date: Sat, 4 Mar 2017 19:13:01 +1300 Subject: [PATCH] Display the boats competing in the race - Moved displayStartingBoats() and displayFinishingOrder() into the Race class - Display the competing boats when the application starts - #implement --- src/main/java/seng302/App.java | 27 ++++++---------------- src/main/java/seng302/Boat.java | 1 - src/main/java/seng302/Race.java | 40 ++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index 9c5f2b15..0000a5cb 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -4,29 +4,16 @@ import java.util.ArrayList; 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 ) { Race race = new Race(); + race.addBoat(new Boat("Team 1")); + race.addBoat(new Boat("Team 2")); - displayFinishingOrder(race); + race.displayStartingBoats(); + + System.out.println(""); + + race.displayFinishingOrder(); } } \ No newline at end of file diff --git a/src/main/java/seng302/Boat.java b/src/main/java/seng302/Boat.java index 3361e965..670aa04b 100644 --- a/src/main/java/seng302/Boat.java +++ b/src/main/java/seng302/Boat.java @@ -9,7 +9,6 @@ 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 index 32ab5c56..9edc840d 100644 --- a/src/main/java/seng302/Race.java +++ b/src/main/java/seng302/Race.java @@ -25,7 +25,7 @@ public class Race { /* Returns a list of boats in the order that they - finished the race (position 0 is first) + finished the race (position 0 is first place) @returns a list of boats */ @@ -45,4 +45,42 @@ public class Race { public int getNumberOfBoats(){ return numberOfBoats; } + + /* + Returns a list of boats in the race + + @returns a list of the boats competing in the race + */ + public Boat[] getBoats(){ + return boats.toArray(new Boat[boats.size()]); + } + + /* + Prints the order in which the boats finished + */ + public void displayFinishingOrder(){ + int numberOfBoats = this.getNumberOfBoats(); + Boat[] boats = this.getFinishedBoats(); + + System.out.println("--- Finishing Order ---"); + + for (int i = 0; i < numberOfBoats; i++) { + System.out.println("#" + Integer.toString(i+1) + " - " + boats[i].getTeamName()); + } + } + + /* + Prints the list of boats competing in the race + + */ + public void displayStartingBoats(){ + int numberOfBoats = this.getNumberOfBoats(); + Boat[] boats = this.getBoats(); + + System.out.println("--- Competing Boats ---"); + + for (int i = 0; i < numberOfBoats; i++) { + System.out.println(boats[i].getTeamName()); + } + } } \ No newline at end of file