Implemented leg class and added legs to the race

- #implement
This commit is contained in:
Michael Rausch
2017-03-06 17:56:07 +13:00
parent 597c1ae955
commit 9453307fd4
2 changed files with 59 additions and 1 deletions
+47
View File
@@ -0,0 +1,47 @@
package seng302;
public class Leg {
private int heading;
private int distance;
private String startLabel;
private boolean isFinishingLeg;
public Leg(int heading, int distance, String label){
this.heading = heading;
this.distance = distance;
this.startLabel = label;
this.isFinishingLeg = false;
}
public void setHeading(int heading){
this.heading = heading;
}
public int getHeading(){
return this.heading;
}
public void setDistance(int distance){
this.distance = distance;
}
public int getDistance(){
return this.distance;
}
public void setLabel(String label){
this.startLabel = label;
}
public String getLabel(){
return this.startLabel;
}
public void setFinishingLeg(boolean isFinishingLeg){
this.isFinishingLeg = isFinishingLeg;
}
public boolean getIsFinishingLeg(){
return this.isFinishingLeg;
}
}
+12 -1
View File
@@ -8,10 +8,12 @@ import java.util.List;
public class Race {
private ArrayList<Boat> boats;
private ArrayList<Leg> legs;
private int numberOfBoats = 0;
public Race(){
boats = new ArrayList<Boat>();
legs = new ArrayList<Leg>();
}
/*
@@ -71,7 +73,6 @@ public class Race {
/*
Prints the list of boats competing in the race
*/
public void displayStartingBoats(){
int numberOfBoats = this.getNumberOfBoats();
@@ -83,4 +84,14 @@ public class Race {
System.out.println(boats[i].getTeamName());
}
}
public void addLeg(Leg leg){
this.legs.add(leg);
}
public void printLegs(){
for (Leg leg : this.legs.toArray(new Leg[legs.size()])){
System.out.println(leg.getLabel());
}
}
}