Fixed docstrings

Tags: #docs
This commit is contained in:
Michael Rausch
2017-03-08 22:31:05 +13:00
parent ae80b434f6
commit 0a86dde7e4
2 changed files with 43 additions and 21 deletions
+29 -4
View File
@@ -6,23 +6,48 @@ class Marker {
private String name; private String name;
private ArrayList<Boat> boatOrder; private ArrayList<Boat> boatOrder;
/**
* Represents the marker at the beginning of a leg
*
* @param name, the name of the marker
*/
public Marker(String name){ public Marker(String name){
this.name = name; this.name = name;
this.boatOrder = new ArrayList<Boat>(); this.boatOrder = new ArrayList<Boat>();
} }
public String getName() { /**
return this.name; * 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(){
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()]);
} }
+8 -11
View File
@@ -80,20 +80,19 @@ public class Race {
/** /**
* Returns a list of boats in the race * Returns a list of boats in the race
* *
* @returns a list of the boats competing in the race * @return a list of the boats competing in the race
*/ */
public Boat[] getBoats() { public Boat[] getBoats() {
return boats.toArray(new Boat[boats.size()]); return boats.toArray(new Boat[boats.size()]);
} }
/** /**
* Prints the order in which the boats finished * Prints the order in which the boats finished the race
*/ */
public void displayFinishingOrder() { public void displayFinishingOrder() {
int numberOfBoats = this.getNumberOfBoats(); int numberOfBoats = this.getNumberOfBoats();
Boat[] boats = this.getFinishedBoats(); Boat[] boats = this.getFinishedBoats();
System.out.println("\n\n");
System.out.println("--- Finishing Order ---"); System.out.println("--- Finishing Order ---");
for (int i = 0; i < Array.getLength(boats); i++) { for (int i = 0; i < Array.getLength(boats); i++) {
@@ -147,11 +146,10 @@ public class Race {
} }
/** /**
* Temporary method used to generated all the events. * Generate all events that will happen during the race.
*/ */
private void generateEvents() { private void generateEvents() {
//calculate the time every boat passes each leg, and create an event
//calculate the time for every boat passes each leg, and create an event
for (Boat boat : this.boats) { for (Boat boat : this.boats) {
long totalDistance = 0; long totalDistance = 0;
for (Leg leg : this.legs) { for (Leg leg : this.legs) {
@@ -171,8 +169,7 @@ public class Race {
} }
/** /**
* Note: this function is useless so far * Calculates how far a boat has travelled in meters
* Calculates how far a boat has travelled in meter
* *
* @param velocity the velocity of boat * @param velocity the velocity of boat
* @return a float number of distance the boat has been travelled * @return a float number of distance the boat has been travelled
@@ -194,19 +191,19 @@ public class Race {
long currentTime = (long) ((System.currentTimeMillis() - this.startTime) * this.timeScale); long currentTime = (long) ((System.currentTimeMillis() - this.startTime) * this.timeScale);
if (currentTime > peekEvent.getTime()) { if (currentTime > peekEvent.getTime()) {
// pull out the event
Event nextEvent = events.poll(); Event nextEvent = events.poll();
// I just simply print it out for testing // Display a summary of the event
System.out.println(nextEvent.getEventString()); System.out.println(nextEvent.getEventString());
nextEvent.boatPassedMarker(); nextEvent.boatPassedMarker();
// If event is a boat finishing the race
if (nextEvent.getIsFinishingEvent()) { if (nextEvent.getIsFinishingEvent()) {
this.finishingOrder.add(nextEvent.getBoat()); this.finishingOrder.add(nextEvent.getBoat());
} }
} }
// Wait for 100ms to slow down the while loop // Wait for 100ms to throttle the while loop
try { try {
Thread.sleep(100); Thread.sleep(100);
} catch (java.lang.InterruptedException e) { } catch (java.lang.InterruptedException e) {