Added gate mark and refactored marker to mark #story[378]

This commit is contained in:
Peter
2017-03-16 16:11:48 +13:00
parent 550812d8e1
commit 11c5e1e9ba
5 changed files with 46 additions and 45 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ public class App {
} }
race.addLeg(new Leg(35, 100, "Start")); race.addLeg(new Leg(35, 100, "Start"));
race.addLeg(new Leg(10, 300, "Marker 1")); race.addLeg(new Leg(10, 300, "Mark 1"));
race.addLeg(new Leg(350, 400, "Leeward Gate")); race.addLeg(new Leg(350, 400, "Leeward Gate"));
race.addLeg(new Leg(10, 400, "Windward Gate")); race.addLeg(new Leg(10, 400, "Windward Gate"));
@@ -0,0 +1,20 @@
package seng302.models;
/**
* Created by ptg19 on 16/03/17.
*/
public class GateMark {
private double lat;
private double lon;
private Mark mark1;
private Mark mark2;
private String name;
public GateMark(String name, Mark mark1, Mark mark2, double lat, double lon){
this.lat = lat;
this.lon = lon;
this.mark1 = mark1;
this.mark2 = mark2;
this.name = name;
}
}
+12 -12
View File
@@ -7,19 +7,19 @@ public class Leg {
private int heading; private int heading;
private int distance; private int distance;
private boolean isFinishingLeg; private boolean isFinishingLeg;
private Marker startingMarker; private Mark startingMark;
/** /**
* Create a new leg * Create a new leg
* *
* @param heading, the magnetic heading of this leg * @param heading, the magnetic heading of this leg
* @param distance, the total distance of this leg in meters * @param distance, the total distance of this leg in meters
* @param marker, the marker this leg starts on * @param mark, the mark this leg starts on
*/ */
public Leg(int heading, int distance, Marker marker) { public Leg(int heading, int distance, Mark mark) {
this.heading = heading; this.heading = heading;
this.distance = distance; this.distance = distance;
this.startingMarker = marker; this.startingMark = mark;
this.isFinishingLeg = false; this.isFinishingLeg = false;
} }
@@ -33,7 +33,7 @@ public class Leg {
public Leg(int heading, int distance, String markerName) { public Leg(int heading, int distance, String markerName) {
this.heading = heading; this.heading = heading;
this.distance = distance; this.distance = distance;
this.startingMarker = new Marker(markerName); this.startingMark = new Mark(markerName);
this.isFinishingLeg = false; this.isFinishingLeg = false;
} }
@@ -68,29 +68,29 @@ public class Leg {
/** /**
* Returns the marker this leg started on * Returns the marker this leg started on
*/ */
public Marker getMarker() { public Mark getMarker() {
return this.startingMarker; return this.startingMark;
} }
/** /**
* Set the marker this leg starts on * Set the mark this leg starts on
*/ */
public void setMarker(Marker marker) { public void setMarker(Mark mark) {
this.startingMarker = marker; this.startingMark = mark;
} }
/** /**
* Returns the name of the marker this leg started on * Returns the name of the marker this leg started on
*/ */
public String getMarkerLabel() { public String getMarkerLabel() {
return this.startingMarker.getName(); return this.startingMark.getName();
} }
/** /**
* Tell the marker that the boat has passed it * Tell the marker that the boat has passed it
*/ */
public void addBoatToMarker(Boat boat) { public void addBoatToMarker(Boat boat) {
this.startingMarker.addBoat(boat); this.startingMark.addBoat(boat);
} }
/** /**
@@ -5,7 +5,9 @@ import java.util.ArrayList;
/** /**
* Represents the marker at the beginning of a leg * Represents the marker at the beginning of a leg
*/ */
public class Marker{ public class Mark {
private double lat;
private double lon;
private String name; private String name;
private ArrayList<Boat> boatOrder; private ArrayList<Boat> boatOrder;
@@ -14,43 +16,22 @@ public class Marker{
* *
* @param name, the name of the marker * @param name, the name of the marker
*/ */
public Marker(String name){ public Mark(String name, double lat, double lon){
this.name = name; this.name = name;
this.lat = lat;
this.lon = lon;
this.boatOrder = new ArrayList<Boat>(); this.boatOrder = new ArrayList<Boat>();
} }
/**
* Set the name of the marker
*
* @param name, the name of the marker
*/
public void setName(String name){ public void setName(String name){
this.name = name; this.name = name;
} }
/**
* Get the name of the marker
*
* @return the name of the marker
*/
public String getName(){ public String getName(){
return this.name; return this.name;
} }
/**
* Add a boat as they pass the marker
*
* @param boat, the boat that passed the marker
*/
public void addBoat(Boat boat){ public void addBoat(Boat boat){
this.boatOrder.add(boat); this.boatOrder.add(boat);
} }
/**
* Get a list of boats in the order they passed the marker
*
* @return An array of boats in the order they passed the marker
*/
public Boat[] getBoats(){ public Boat[] getBoats(){
return this.boatOrder.toArray(new Boat[this.boatOrder.size()]); return this.boatOrder.toArray(new Boat[this.boatOrder.size()]);
} }
+7 -7
View File
@@ -2,7 +2,7 @@ package seng302;
import org.junit.Test; import org.junit.Test;
import seng302.models.Leg; import seng302.models.Leg;
import seng302.models.Marker; import seng302.models.Mark;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -17,25 +17,25 @@ public class LegTest {
*/ */
@Test @Test
public void testLegCreationUsingMarkerLabel() { public void testLegCreationUsingMarkerLabel() {
Leg leg = new Leg(010, 100, "Marker"); Leg leg = new Leg(010, 100, "Mark");
assertEquals(leg.getHeading(), 010); assertEquals(leg.getHeading(), 010);
assertEquals(leg.getDistance(), 100); assertEquals(leg.getDistance(), 100);
assertEquals(leg.getMarkerLabel(), "Marker"); assertEquals(leg.getMarkerLabel(), "Mark");
assertEquals(leg.getIsFinishingLeg(), false); assertEquals(leg.getIsFinishingLeg(), false);
} }
/** /**
* Test creation of the leg by providing a * Test creation of the leg by providing a
* Marker object * Mark object
*/ */
@Test @Test
public void testLegCreation() { public void testLegCreation() {
Leg leg = new Leg(010, 100, new Marker("Marker")); Leg leg = new Leg(010, 100, new Mark("Mark"));
assertEquals(leg.getHeading(), 010); assertEquals(leg.getHeading(), 010);
assertEquals(leg.getDistance(), 100); assertEquals(leg.getDistance(), 100);
assertEquals(leg.getMarkerLabel(), "Marker"); assertEquals(leg.getMarkerLabel(), "Mark");
assertEquals(leg.getIsFinishingLeg(), false); assertEquals(leg.getIsFinishingLeg(), false);
} }
@@ -45,7 +45,7 @@ public class LegTest {
*/ */
@Test @Test
public void testSetFinishLeg() { public void testSetFinishLeg() {
Leg leg = new Leg(010, 100, "Marker"); Leg leg = new Leg(010, 100, "Mark");
leg.setFinishingLeg(true); leg.setFinishingLeg(true);
assertEquals(leg.getIsFinishingLeg(), true); assertEquals(leg.getIsFinishingLeg(), true);