Merge branch 'story1-team-names' into 'master'

Now displays the names of teams entered into the race



See merge request !3
This commit is contained in:
Michael Rausch
2017-03-04 19:32:33 +13:00
5 changed files with 66 additions and 23 deletions
+7 -20
View File
@@ -4,29 +4,16 @@ 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 )
{ {
Race race = new Race(); 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();
} }
} }
-1
View File
@@ -9,7 +9,6 @@ public class Boat
{ {
// The name of the team, this is also the name of the boat // The name of the team, this is also the name of the boat
private String teamName = null; private String teamName = null;
private boolean finishedRace = false;
public Boat(String teamName) { public Boat(String teamName) {
this.teamName = teamName; this.teamName = teamName;
+39 -1
View File
@@ -25,7 +25,7 @@ public class Race {
/* /*
Returns a list of boats in the order that they 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 @returns a list of boats
*/ */
@@ -45,4 +45,42 @@ public class Race {
public int getNumberOfBoats(){ public int getNumberOfBoats(){
return numberOfBoats; 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());
}
}
} }
+1
View File
@@ -9,6 +9,7 @@ import static org.junit.Assert.assertEquals;
*/ */
public class BoatTest public class BoatTest
{ {
@Test @Test
public void testBoatCreation() public void testBoatCreation()
{ {
+19 -1
View File
@@ -10,8 +10,11 @@ import java.lang.reflect.Array;
*/ */
public class RaceTest public class RaceTest
{ {
/*
Test that all boats that were added to the race also finish the race
*/
@Test @Test
public void testAddingBoatsToRace() public void testFinishingBoats()
{ {
Boat boat1 = new Boat("Team 1"); Boat boat1 = new Boat("Team 1");
Boat boat2 = new Boat("Team 2"); Boat boat2 = new Boat("Team 2");
@@ -24,4 +27,19 @@ public class RaceTest
assertEquals(Array.getLength(race.getFinishedBoats()), 3); assertEquals(Array.getLength(race.getFinishedBoats()), 3);
} }
/*
Test that all boats were added to the race
*/
@Test
public void testAddingBoatsToRace(){
Boat boat1 = new Boat("Team 1");
Boat boat2 = new Boat("Team 2");
Race race = new Race();
race.addBoat(boat1);
race.addBoat(boat2);
assertEquals(Array.getLength(boats.getBoats()), 2);
}
} }