mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Reformatted doctring and import statements
This commit is contained in:
@@ -1,87 +1,86 @@
|
||||
package seng302;
|
||||
|
||||
import java.util.*;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class App
|
||||
{
|
||||
/**
|
||||
* Builds a race object for the AC35 course
|
||||
*/
|
||||
public static Race createRace() throws Exception{
|
||||
Race race = new Race();
|
||||
public class App {
|
||||
/**
|
||||
* Builds a race object for the AC35 course
|
||||
*/
|
||||
public static Race createRace() throws Exception {
|
||||
Race race = new Race();
|
||||
|
||||
// Read team names from file
|
||||
FileParser fp = new FileParser("doc/examples/config.json");
|
||||
ArrayList<String> boatNames = new ArrayList<>();
|
||||
ArrayList<Map<String, Object>> teams = fp.getTeams();
|
||||
// Read team names from file
|
||||
FileParser fp = new FileParser("doc/examples/config.json");
|
||||
ArrayList<String> boatNames = new ArrayList<>();
|
||||
ArrayList<Map<String, Object>> teams = fp.getTeams();
|
||||
|
||||
//get race size
|
||||
int numberOfBoats = (int) fp.getRaceSize();
|
||||
//get race size
|
||||
int numberOfBoats = (int) fp.getRaceSize();
|
||||
|
||||
//get time scale
|
||||
double timeScale = fp.getTimeScale();
|
||||
race.setTimeScale(timeScale);
|
||||
//get time scale
|
||||
double timeScale = fp.getTimeScale();
|
||||
race.setTimeScale(timeScale);
|
||||
|
||||
for (Map<String, Object> team : teams) {
|
||||
boatNames.add((String) team.get("team-name"));
|
||||
}
|
||||
for (Map<String, Object> team : teams) {
|
||||
boatNames.add((String) team.get("team-name"));
|
||||
}
|
||||
|
||||
// Shuffle team names
|
||||
long seed = System.nanoTime();
|
||||
Collections.shuffle(boatNames, new Random(seed));
|
||||
// Shuffle team names
|
||||
long seed = System.nanoTime();
|
||||
Collections.shuffle(boatNames, new Random(seed));
|
||||
|
||||
if (numberOfBoats > Array.getLength(boatNames.toArray())){
|
||||
return null;
|
||||
}
|
||||
if (numberOfBoats > Array.getLength(boatNames.toArray())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < numberOfBoats; i++) {
|
||||
race.addBoat(new Boat(boatNames.get(i), (Double)(teams.get(i).get("velocity"))));
|
||||
}
|
||||
for (int i = 0; i < numberOfBoats; i++) {
|
||||
race.addBoat(new Boat(boatNames.get(i), (Double) (teams.get(i).get("velocity"))));
|
||||
}
|
||||
|
||||
race.addLeg(new Leg(35, 100, "Start"));
|
||||
race.addLeg(new Leg(10, 300, "Marker 1"));
|
||||
race.addLeg(new Leg(350, 400, "Leeward Gate"));
|
||||
race.addLeg(new Leg(10, 400, "Windward Gate"));
|
||||
race.addLeg(new Leg(35, 100, "Start"));
|
||||
race.addLeg(new Leg(10, 300, "Marker 1"));
|
||||
race.addLeg(new Leg(350, 400, "Leeward Gate"));
|
||||
race.addLeg(new Leg(10, 400, "Windward Gate"));
|
||||
|
||||
Leg finishingLeg = new Leg(10, 400, "Leeward Gate");
|
||||
finishingLeg.setFinishingLeg(true);
|
||||
Leg finishingLeg = new Leg(10, 400, "Leeward Gate");
|
||||
finishingLeg.setFinishingLeg(true);
|
||||
|
||||
race.addLeg(finishingLeg);
|
||||
race.addLeg(finishingLeg);
|
||||
|
||||
return race;
|
||||
}
|
||||
return race;
|
||||
}
|
||||
|
||||
public static void main( String[] args )
|
||||
{
|
||||
Race race = null;
|
||||
public static void main(String[] args) {
|
||||
Race race = null;
|
||||
|
||||
try{
|
||||
race = createRace();
|
||||
}
|
||||
catch (Exception e){
|
||||
System.out.println(e);
|
||||
}
|
||||
try {
|
||||
race = createRace();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
// If race was created
|
||||
if (race != null){
|
||||
race.displayStartingBoats();
|
||||
// If race was created
|
||||
if (race != null) {
|
||||
race.displayStartingBoats();
|
||||
|
||||
System.out.println("\n\n");
|
||||
System.out.println("######################");
|
||||
System.out.println("# Live Race Updates ");
|
||||
System.out.println("######################");
|
||||
race.startRace();
|
||||
System.out.println("\n\n");
|
||||
System.out.println("######################");
|
||||
System.out.println("# Live Race Updates ");
|
||||
System.out.println("######################");
|
||||
race.startRace();
|
||||
|
||||
System.out.println("\n\n");
|
||||
System.out.println("######################");
|
||||
System.out.println("# Race Results ");
|
||||
System.out.println("######################");
|
||||
race.showRaceMarkerResults();
|
||||
race.displayFinishingOrder();
|
||||
}
|
||||
else{
|
||||
System.out.println("There was an error creating the race.");
|
||||
}
|
||||
System.out.println("\n\n");
|
||||
System.out.println("######################");
|
||||
System.out.println("# Race Results ");
|
||||
System.out.println("######################");
|
||||
race.showRaceMarkerResults();
|
||||
race.displayFinishingOrder();
|
||||
} else {
|
||||
System.out.println("There was an error creating the race.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +1,60 @@
|
||||
package seng302;
|
||||
|
||||
/**
|
||||
* Represents a boat in the race.
|
||||
*
|
||||
* @param teamName The name of the team sailing the boat
|
||||
* @param boatVelocity The speed of the boat in meters/second
|
||||
*/
|
||||
public class Boat
|
||||
{
|
||||
|
||||
private String teamName; // The name of the team, this is also the name of the boat
|
||||
private double velocity; // In meters/second
|
||||
|
||||
public Boat(String teamName) {
|
||||
this.teamName = teamName;
|
||||
this.velocity = 10; // Default velocity
|
||||
}
|
||||
public class Boat {
|
||||
|
||||
public Boat(String teamName, double boatVelocity) {
|
||||
this.teamName = teamName;
|
||||
this.velocity = boatVelocity;
|
||||
}
|
||||
private String teamName; // The name of the team, this is also the name of the boat
|
||||
private double velocity; // In meters/second
|
||||
|
||||
/**
|
||||
* Returns the name of the team sailing the boat
|
||||
* @return The name of the team
|
||||
*/
|
||||
public String getTeamName(){
|
||||
return this.teamName;
|
||||
}
|
||||
public Boat(String teamName) {
|
||||
this.teamName = teamName;
|
||||
this.velocity = 10; // Default velocity
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the team sailing the boat
|
||||
* @param teamName The name of the team
|
||||
*/
|
||||
public void setTeamName(String teamName){
|
||||
this.teamName = teamName;
|
||||
}
|
||||
/**
|
||||
* Represents a boat in the race.
|
||||
*
|
||||
* @param teamName The name of the team sailing the boat
|
||||
* @param boatVelocity The speed of the boat in meters/second
|
||||
*/
|
||||
public Boat(String teamName, double boatVelocity) {
|
||||
this.teamName = teamName;
|
||||
this.velocity = boatVelocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets velocity of the boat
|
||||
* @param velocity The velocity of boat
|
||||
*/
|
||||
public void setVelocity(float velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
/**
|
||||
* Returns the name of the team sailing the boat
|
||||
*
|
||||
* @return The name of the team
|
||||
*/
|
||||
public String getTeamName() {
|
||||
return this.teamName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets velocity of the boat
|
||||
* @return a float number of the boat velocity
|
||||
*/
|
||||
public double getVelocity() {
|
||||
return this.velocity;
|
||||
}
|
||||
/**
|
||||
* Sets the name of the team sailing the boat
|
||||
*
|
||||
* @param teamName The name of the team
|
||||
*/
|
||||
public void setTeamName(String teamName) {
|
||||
this.teamName = teamName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets velocity of the boat
|
||||
*
|
||||
* @return a float number of the boat velocity
|
||||
*/
|
||||
public double getVelocity() {
|
||||
return this.velocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets velocity of the boat
|
||||
*
|
||||
* @param velocity The velocity of boat
|
||||
*/
|
||||
public void setVelocity(float velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
}
|
||||
@@ -3,117 +3,125 @@ package seng302;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Event class containing the time of specific event, related team/boat, and
|
||||
* event location such as leg.
|
||||
*
|
||||
* @param eventTime, what time the event happens
|
||||
* @param eventBoat, the boat that the event belongs to
|
||||
* @param eventLeg, the leg the event happens on
|
||||
*/
|
||||
|
||||
public class Event {
|
||||
|
||||
private long time;
|
||||
private Boat boat;
|
||||
private Leg leg;
|
||||
private boolean isFinishingEvent = false;
|
||||
private long time;
|
||||
private Boat boat;
|
||||
private Leg leg;
|
||||
private boolean isFinishingEvent = false;
|
||||
|
||||
public Event(long eventTime, Boat eventBoat, Leg eventLeg) {
|
||||
this.time = eventTime;
|
||||
this.boat = eventBoat;
|
||||
this.leg = eventLeg;
|
||||
}
|
||||
/**
|
||||
* Event class containing the time of specific event, related team/boat, and
|
||||
* event location such as leg.
|
||||
*
|
||||
* @param eventTime, what time the event happens
|
||||
* @param eventBoat, the boat that the event belongs to
|
||||
* @param eventLeg, the leg the event happens on
|
||||
*/
|
||||
public Event(long eventTime, Boat eventBoat, Leg eventLeg) {
|
||||
this.time = eventTime;
|
||||
this.boat = eventBoat;
|
||||
this.leg = eventLeg;
|
||||
}
|
||||
|
||||
public Event(long eventTime, Boat eventBoat, Leg eventLeg, boolean isFinishingEvent) {
|
||||
this.time = eventTime;
|
||||
this.boat = eventBoat;
|
||||
this.leg = eventLeg;
|
||||
this.isFinishingEvent = isFinishingEvent;
|
||||
}
|
||||
public Event(long eventTime, Boat eventBoat, Leg eventLeg, boolean isFinishingEvent) {
|
||||
this.time = eventTime;
|
||||
this.boat = eventBoat;
|
||||
this.leg = eventLeg;
|
||||
this.isFinishingEvent = isFinishingEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time for the event
|
||||
* @param eventTime the time for event in millisecond
|
||||
*/
|
||||
public void setTime(long eventTime) {
|
||||
this.time = eventTime;
|
||||
}
|
||||
/**
|
||||
* Gets the time for the event
|
||||
*
|
||||
* @return the time for event in millisecond
|
||||
*/
|
||||
public long getTime() {
|
||||
return this.time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time for the event
|
||||
* @return the time for event in millisecond
|
||||
*/
|
||||
public long getTime() {
|
||||
return this.time;
|
||||
}
|
||||
/**
|
||||
* Sets the time for the event
|
||||
*
|
||||
* @param eventTime the time for event in millisecond
|
||||
*/
|
||||
public void setTime(long eventTime) {
|
||||
this.time = eventTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time in a formatted string
|
||||
* @return the string of time
|
||||
*/
|
||||
public String getTimeString() {
|
||||
return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(time));
|
||||
}
|
||||
/**
|
||||
* Gets the time in a formatted string
|
||||
*
|
||||
* @return the string of time
|
||||
*/
|
||||
public String getTimeString() {
|
||||
return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(time));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the involved boat
|
||||
* @param eventBoat the involved boat
|
||||
*/
|
||||
public void setBoat(Boat eventBoat) {
|
||||
this.boat = eventBoat;
|
||||
}
|
||||
/**
|
||||
* Gets the involved boat
|
||||
*
|
||||
* @return the boat involved in the event
|
||||
*/
|
||||
public Boat getBoat() {
|
||||
return this.boat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the involved boat
|
||||
* @return the boat involved in the event
|
||||
*/
|
||||
public Boat getBoat() {
|
||||
return this.boat;
|
||||
}
|
||||
/**
|
||||
* Sets the involved boat
|
||||
*
|
||||
* @param eventBoat the involved boat
|
||||
*/
|
||||
public void setBoat(Boat eventBoat) {
|
||||
this.boat = eventBoat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the involved location/leg
|
||||
* @param eventLeg the involved leg
|
||||
*/
|
||||
public void setLeg(Leg eventLeg) {
|
||||
this.leg = eventLeg;
|
||||
}
|
||||
/**
|
||||
* Gets the involved location/leg
|
||||
*
|
||||
* @return the leg involved in the event
|
||||
*/
|
||||
public Leg getLeg() {
|
||||
return this.leg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the involved location/leg
|
||||
* @return the leg involved in the event
|
||||
*/
|
||||
public Leg getLeg() {
|
||||
return this.leg;
|
||||
}
|
||||
/**
|
||||
* Sets the involved location/leg
|
||||
*
|
||||
* @param eventLeg the involved leg
|
||||
*/
|
||||
public void setLeg(Leg eventLeg) {
|
||||
this.leg = eventLeg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call when the boat reaches the marker, this will tell the marker the order
|
||||
* in which boats pass it
|
||||
*/
|
||||
public void addBoatToMarker(){
|
||||
this.leg.addBoatToMarker(boat);
|
||||
}
|
||||
/**
|
||||
* Call when the boat reaches the marker, this will tell the marker the order
|
||||
* in which boats pass it
|
||||
*/
|
||||
public void addBoatToMarker() {
|
||||
this.leg.addBoatToMarker(boat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this event is the boat finishing the race
|
||||
*
|
||||
*/
|
||||
public boolean getIsFinishingEvent(){
|
||||
return this.isFinishingEvent;
|
||||
}
|
||||
/**
|
||||
* Returns true if this event is the boat finishing the race
|
||||
*/
|
||||
public boolean getIsFinishingEvent() {
|
||||
return this.isFinishingEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string that contains the timestamp and course information for this event
|
||||
* @return A string that contains the timestamp and course information for this event
|
||||
*/
|
||||
public String getEventString(){
|
||||
String currentHeading = Integer.toString(this.getLeg().getHeading());
|
||||
/**
|
||||
* Get a string that contains the timestamp and course information for this event
|
||||
*
|
||||
* @return A string that contains the timestamp and course information for this event
|
||||
*/
|
||||
public String getEventString() {
|
||||
String currentHeading = Integer.toString(this.getLeg().getHeading());
|
||||
|
||||
if (this.isFinishingEvent){
|
||||
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " finished the race");
|
||||
}
|
||||
if (this.isFinishingEvent) {
|
||||
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " finished the race");
|
||||
}
|
||||
|
||||
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " passed " + this.getLeg().getMarkerLabel() + " going heading " + currentHeading + "°");
|
||||
}
|
||||
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " passed " + this.getLeg().getMarkerLabel() + " going heading " + currentHeading + "°");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -18,108 +18,115 @@ import java.util.Map;
|
||||
|
||||
public class FileParser {
|
||||
|
||||
private String filePath;
|
||||
private JSONObject content;
|
||||
/** used to construct an instance of file parser
|
||||
*
|
||||
* @param filePath a string like path to show location of desired file to
|
||||
* be parsed
|
||||
*/
|
||||
public FileParser(String filePath) throws Exception {
|
||||
this.filePath = filePath;
|
||||
this.readFile();
|
||||
}
|
||||
private String filePath;
|
||||
private JSONObject content;
|
||||
|
||||
/**
|
||||
* Reads content from a given file, and return the content as JSONObject.
|
||||
* Throws FileNotFoundException, if the given file cannot be found.
|
||||
*/
|
||||
private void readFile() throws FileNotFoundException{
|
||||
JSONParser parser = new JSONParser();
|
||||
try {
|
||||
this.content = (JSONObject) parser.parse(new FileReader(filePath));
|
||||
/**
|
||||
* used to construct an instance of file parser
|
||||
*
|
||||
* @param filePath a string like path to show location of desired file to
|
||||
* be parsed
|
||||
*/
|
||||
public FileParser(String filePath) throws Exception {
|
||||
this.filePath = filePath;
|
||||
this.readFile();
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Reads content from a given file, and return the content as JSONObject.
|
||||
* Throws FileNotFoundException, if the given file cannot be found.
|
||||
*/
|
||||
private void readFile() throws FileNotFoundException {
|
||||
JSONParser parser = new JSONParser();
|
||||
try {
|
||||
this.content = (JSONObject) parser.parse(new FileReader(filePath));
|
||||
|
||||
/**
|
||||
* Gets time scale setting parameter.
|
||||
* @return long time scale. -1 if parameter is invalid (eg. scale is
|
||||
* negative number, or containing non numeric character) or cannot be found.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public double getTimeScale() {
|
||||
try {
|
||||
double timeScale = (double) this.content.get("time-scale");
|
||||
return timeScale >= 0 ? timeScale : -1;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets race name in the setting file.
|
||||
* @return a string of race name. null if race name is invalid or cannot
|
||||
* be found.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getRaceName() {
|
||||
try {
|
||||
return (String) this.content.get("race-name");
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets time scale setting parameter.
|
||||
*
|
||||
* @return long time scale. -1 if parameter is invalid (eg. scale is
|
||||
* negative number, or containing non numeric character) or cannot be found.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public double getTimeScale() {
|
||||
try {
|
||||
double timeScale = (double) this.content.get("time-scale");
|
||||
return timeScale >= 0 ? timeScale : -1;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of teams who participate the race.
|
||||
* @return an ArrayList containing strings of team names. null if teams
|
||||
* setting is invalid or there is no team.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ArrayList<Map<String, Object>> getTeams() {
|
||||
try {
|
||||
return (ArrayList<Map<String, Object>>) this.content.get("teams");
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets race name in the setting file.
|
||||
*
|
||||
* @return a string of race name. null if race name is invalid or cannot
|
||||
* be found.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getRaceName() {
|
||||
try {
|
||||
return (String) this.content.get("race-name");
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total number of teams.
|
||||
* @return the number of teams. 0 if no teams or anything goes wrong.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public long getTotalNumberOfTeams() {
|
||||
ArrayList<Map<String, Object>> teams = getTeams();
|
||||
try {
|
||||
return teams.size();
|
||||
} catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets an array of teams who participate the race.
|
||||
*
|
||||
* @return an ArrayList containing strings of team names. null if teams
|
||||
* setting is invalid or there is no team.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ArrayList<Map<String, Object>> getTeams() {
|
||||
try {
|
||||
return (ArrayList<Map<String, Object>>) this.content.get("teams");
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of boats that would compete during a race. Returns the
|
||||
* total number of race size if parameter is invalid or cannot be found.
|
||||
* @return an int of the race size.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public long getRaceSize() {
|
||||
long totalTeams = this.getTotalNumberOfTeams();
|
||||
try {
|
||||
long raceSize = (long) this.content.get("race-size");
|
||||
return raceSize >= 0 && raceSize <= totalTeams? raceSize : totalTeams;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return totalTeams;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets the total number of teams.
|
||||
*
|
||||
* @return the number of teams. 0 if no teams or anything goes wrong.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public long getTotalNumberOfTeams() {
|
||||
ArrayList<Map<String, Object>> teams = getTeams();
|
||||
try {
|
||||
return teams.size();
|
||||
} catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of boats that would compete during a race. Returns the
|
||||
* total number of race size if parameter is invalid or cannot be found.
|
||||
*
|
||||
* @return an int of the race size.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public long getRaceSize() {
|
||||
long totalTeams = this.getTotalNumberOfTeams();
|
||||
try {
|
||||
long raceSize = (long) this.content.get("race-size");
|
||||
return raceSize >= 0 && raceSize <= totalTeams ? raceSize : totalTeams;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return totalTeams;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,108 +1,108 @@
|
||||
package seng302;
|
||||
|
||||
public class Leg {
|
||||
private int heading;
|
||||
private int distance;
|
||||
private boolean isFinishingLeg;
|
||||
private Marker startingMarker;
|
||||
private int heading;
|
||||
private int distance;
|
||||
private boolean isFinishingLeg;
|
||||
private Marker startingMarker;
|
||||
|
||||
/*
|
||||
Create a new leg
|
||||
/**
|
||||
* Create a new leg
|
||||
*
|
||||
* @param heading, the magnetic heading of this leg
|
||||
* @param distance, the total distance of this leg in meters
|
||||
* @param marker, the marker this leg starts on
|
||||
*/
|
||||
public Leg(int heading, int distance, Marker marker) {
|
||||
this.heading = heading;
|
||||
this.distance = distance;
|
||||
this.startingMarker = marker;
|
||||
this.isFinishingLeg = false;
|
||||
}
|
||||
|
||||
@param heading, the magnetic heading of this leg
|
||||
@param distance, the total distance of this leg in meters
|
||||
@param marker, the marker this leg starts on
|
||||
*/
|
||||
public Leg(int heading, int distance, Marker marker){
|
||||
this.heading = heading;
|
||||
this.distance = distance;
|
||||
this.startingMarker = marker;
|
||||
this.isFinishingLeg = false;
|
||||
}
|
||||
/**
|
||||
* Create a new leg
|
||||
*
|
||||
* @param heading, the magnetic heading of this leg
|
||||
* @param distance, the total distance of this leg in meters
|
||||
* @param markerName, the name of the marker this leg starts on
|
||||
*/
|
||||
public Leg(int heading, int distance, String markerName) {
|
||||
this.heading = heading;
|
||||
this.distance = distance;
|
||||
this.startingMarker = new Marker(markerName);
|
||||
this.isFinishingLeg = false;
|
||||
}
|
||||
|
||||
/*
|
||||
Create a new leg
|
||||
/**
|
||||
* Get the heading of this leg
|
||||
*/
|
||||
public int getHeading() {
|
||||
return this.heading;
|
||||
}
|
||||
|
||||
@param heading, the magnetic heading of this leg
|
||||
@param distance, the total distance of this leg in meters
|
||||
@param markerName, the name of the marker this leg starts on
|
||||
*/
|
||||
public Leg(int heading, int distance, String markerName){
|
||||
this.heading = heading;
|
||||
this.distance = distance;
|
||||
this.startingMarker = new Marker(markerName);
|
||||
this.isFinishingLeg = false;
|
||||
}
|
||||
/**
|
||||
* Set the heading for this leg
|
||||
*/
|
||||
public void setHeading(int heading) {
|
||||
this.heading = heading;
|
||||
}
|
||||
|
||||
/*
|
||||
Set the heading for this leg
|
||||
*/
|
||||
public void setHeading(int heading){
|
||||
this.heading = heading;
|
||||
}
|
||||
/**
|
||||
* Get the total distance of this leg in meters
|
||||
*/
|
||||
public int getDistance() {
|
||||
return this.distance;
|
||||
}
|
||||
|
||||
/*
|
||||
Get the heading of this leg
|
||||
*/
|
||||
public int getHeading(){
|
||||
return this.heading;
|
||||
}
|
||||
/**
|
||||
* Set the distance of this leg in meters
|
||||
*/
|
||||
public void setDistance(int distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
/*
|
||||
Set the distance of this leg in meters
|
||||
*/
|
||||
public void setDistance(int distance){
|
||||
this.distance = distance;
|
||||
}
|
||||
/**
|
||||
* Returns the marker this leg started on
|
||||
*/
|
||||
public Marker getMarker() {
|
||||
return this.startingMarker;
|
||||
}
|
||||
|
||||
/*
|
||||
Get the total distance of this leg in meters
|
||||
*/
|
||||
public int getDistance(){
|
||||
return this.distance;
|
||||
}
|
||||
/**
|
||||
* Set the marker this leg starts on
|
||||
*/
|
||||
public void setMarker(Marker marker) {
|
||||
this.startingMarker = marker;
|
||||
}
|
||||
|
||||
/*
|
||||
Set the marker this leg starts on
|
||||
*/
|
||||
public void setMarker(Marker marker){
|
||||
this.startingMarker = marker;
|
||||
}
|
||||
/**
|
||||
* Returns the name of the marker this leg started on
|
||||
*/
|
||||
public String getMarkerLabel() {
|
||||
return this.startingMarker.getName();
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the marker this leg started on
|
||||
*/
|
||||
public Marker getMarker(){
|
||||
return this.startingMarker;
|
||||
}
|
||||
/**
|
||||
* Tell the marker that the boat has passed it
|
||||
*/
|
||||
public void addBoatToMarker(Boat boat) {
|
||||
this.startingMarker.addBoat(boat);
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the name of the marker this leg started on
|
||||
*/
|
||||
public String getMarkerLabel(){
|
||||
return this.startingMarker.getName();
|
||||
}
|
||||
/**
|
||||
* Specify whether or not the race finishes on this leg
|
||||
*
|
||||
* @param isFinishingLeg whether or not the race finishes on this leg
|
||||
*/
|
||||
public void setFinishingLeg(boolean isFinishingLeg) {
|
||||
this.isFinishingLeg = isFinishingLeg;
|
||||
}
|
||||
|
||||
/*
|
||||
Tell the marker that the boat has passed it
|
||||
*/
|
||||
public void addBoatToMarker(Boat boat){
|
||||
this.startingMarker.addBoat(boat);
|
||||
}
|
||||
|
||||
/*
|
||||
Specify whether or not the race finishes on this leg
|
||||
|
||||
@param isFinishingLeg whether or not the race finishes on this leg
|
||||
*/
|
||||
public void setFinishingLeg(boolean isFinishingLeg){
|
||||
this.isFinishingLeg = isFinishingLeg;
|
||||
}
|
||||
|
||||
/*
|
||||
@returns true if this the race finishes after this leg
|
||||
*/
|
||||
public boolean getIsFinishingLeg(){
|
||||
return this.isFinishingLeg;
|
||||
}
|
||||
/**
|
||||
* @returns true if this the race finishes after this leg
|
||||
*/
|
||||
public boolean getIsFinishingLeg() {
|
||||
return this.isFinishingLeg;
|
||||
}
|
||||
}
|
||||
@@ -2,28 +2,28 @@ package seng302;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
class Marker{
|
||||
private String name;
|
||||
private ArrayList<Boat> boatOrder;
|
||||
class Marker {
|
||||
private String name;
|
||||
private ArrayList<Boat> boatOrder;
|
||||
|
||||
public Marker(String name){
|
||||
this.name = name;
|
||||
this.boatOrder = new ArrayList<Boat>();
|
||||
}
|
||||
public Marker(String name) {
|
||||
this.name = name;
|
||||
this.boatOrder = new ArrayList<Boat>();
|
||||
}
|
||||
|
||||
public void setName(String name){
|
||||
this.name = name;
|
||||
}
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addBoat(Boat boat){
|
||||
this.boatOrder.add(boat);
|
||||
}
|
||||
public void addBoat(Boat boat) {
|
||||
this.boatOrder.add(boat);
|
||||
}
|
||||
|
||||
public Boat[] getBoats(){
|
||||
return this.boatOrder.toArray(new Boat[this.boatOrder.size()]);
|
||||
}
|
||||
public Boat[] getBoats() {
|
||||
return this.boatOrder.toArray(new Boat[this.boatOrder.size()]);
|
||||
}
|
||||
}
|
||||
+207
-207
@@ -1,246 +1,246 @@
|
||||
package seng302;
|
||||
|
||||
import java.util.*;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.*;
|
||||
|
||||
public class Race {
|
||||
private ArrayList<Boat> boats; // The boats in the race
|
||||
private ArrayList<Leg> legs; // The legs in the race
|
||||
private ArrayList<Boat> finishingOrder; // The order in which the boats finish the race
|
||||
private PriorityQueue<Event> events; // The events that occur in the race
|
||||
private int numberOfBoats = 0;
|
||||
private long startTime = 0;
|
||||
private double timeScale = 1;
|
||||
private ArrayList<Boat> boats; // The boats in the race
|
||||
private ArrayList<Leg> legs; // The legs in the race
|
||||
private ArrayList<Boat> finishingOrder; // The order in which the boats finish the race
|
||||
private PriorityQueue<Event> events; // The events that occur in the race
|
||||
private int numberOfBoats = 0;
|
||||
private long startTime = 0;
|
||||
private double timeScale = 1;
|
||||
|
||||
public Race() {
|
||||
this.boats = new ArrayList<Boat>();
|
||||
this.legs = new ArrayList<Leg>();
|
||||
this.finishingOrder = new ArrayList<Boat>();
|
||||
public Race() {
|
||||
this.boats = new ArrayList<Boat>();
|
||||
this.legs = new ArrayList<Leg>();
|
||||
this.finishingOrder = new ArrayList<Boat>();
|
||||
|
||||
// create a priority queue with a custom Comparator to order events
|
||||
this.events = new PriorityQueue<Event>(new Comparator<Event>() {
|
||||
@Override
|
||||
public int compare(Event o1, Event o2) {
|
||||
Long time1 = o1.getTime();
|
||||
Long time2 = o2.getTime();
|
||||
// create a priority queue with a custom Comparator to order events
|
||||
this.events = new PriorityQueue<Event>(new Comparator<Event>() {
|
||||
@Override
|
||||
public int compare(Event o1, Event o2) {
|
||||
Long time1 = o1.getTime();
|
||||
Long time2 = o2.getTime();
|
||||
|
||||
// order event asc. by time. if tie appears, then order team
|
||||
// name alphabetically.
|
||||
if (time1 != time2) {
|
||||
return time1.compareTo(time2);
|
||||
} else {
|
||||
return o1.getBoat().getTeamName().compareTo(o2.getBoat().getTeamName());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// order event asc. by time. if tie appears, then order team
|
||||
// name alphabetically.
|
||||
if (time1 != time2) {
|
||||
return time1.compareTo(time2);
|
||||
} else {
|
||||
return o1.getBoat().getTeamName().compareTo(o2.getBoat().getTeamName());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
Add a boat to the race
|
||||
@param boat, the boat to add
|
||||
*/
|
||||
public void addBoat(Boat boat) {
|
||||
boats.add(boat);
|
||||
numberOfBoats += 1;
|
||||
}
|
||||
/**
|
||||
* Add a boat to the race
|
||||
*
|
||||
* @param boat, the boat to add
|
||||
*/
|
||||
public void addBoat(Boat boat) {
|
||||
boats.add(boat);
|
||||
numberOfBoats += 1;
|
||||
}
|
||||
|
||||
/*
|
||||
Returns a list of boats in a random order
|
||||
/**
|
||||
* Returns a list of boats in a random order
|
||||
*
|
||||
* @returns a list of boats
|
||||
*/
|
||||
public Boat[] getShuffledBoats() {
|
||||
// Shuffle the list of boats
|
||||
long seed = System.nanoTime();
|
||||
Collections.shuffle(this.boats, new Random(seed));
|
||||
|
||||
@returns a list of boats
|
||||
*/
|
||||
public Boat[] getShuffledBoats() {
|
||||
// Shuffle the list of boats
|
||||
long seed = System.nanoTime();
|
||||
Collections.shuffle(this.boats, new Random(seed));
|
||||
return boats.toArray(new Boat[boats.size()]);
|
||||
}
|
||||
|
||||
return boats.toArray(new Boat[boats.size()]);
|
||||
}
|
||||
/**
|
||||
* Returns a list of boats in the order that they
|
||||
* finished the race (position 0 is first place)
|
||||
*
|
||||
* @returns a list of boats
|
||||
*/
|
||||
public Boat[] getFinishedBoats() {
|
||||
return this.finishingOrder.toArray(new Boat[this.finishingOrder.size()]);
|
||||
}
|
||||
|
||||
/*
|
||||
Returns a list of boats in the order that they
|
||||
finished the race (position 0 is first place)
|
||||
/**
|
||||
* Returns the number of boats in the race
|
||||
*
|
||||
* @returns the number of boats in the race
|
||||
*/
|
||||
public int getNumberOfBoats() {
|
||||
return numberOfBoats;
|
||||
}
|
||||
|
||||
@returns a list of boats
|
||||
*/
|
||||
public Boat[] getFinishedBoats() {
|
||||
return this.finishingOrder.toArray(new Boat[this.finishingOrder.size()]);
|
||||
}
|
||||
/**
|
||||
* 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()]);
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the number of boats in the race
|
||||
/**
|
||||
* Prints the order in which the boats finished
|
||||
*/
|
||||
public void displayFinishingOrder() {
|
||||
int numberOfBoats = this.getNumberOfBoats();
|
||||
Boat[] boats = this.getFinishedBoats();
|
||||
|
||||
@returns the number of boats in the race
|
||||
*/
|
||||
public int getNumberOfBoats() {
|
||||
return numberOfBoats;
|
||||
}
|
||||
System.out.println("\n\n");
|
||||
System.out.println("--- Finishing Order ---");
|
||||
|
||||
/*
|
||||
Returns a list of boats in the race
|
||||
for (int i = 0; i < Array.getLength(boats); i++) {
|
||||
System.out.println("#" + Integer.toString(i + 1) + " - " + boats[i].getTeamName());
|
||||
}
|
||||
}
|
||||
|
||||
@returns a list of the boats competing in the race
|
||||
*/
|
||||
public Boat[] getBoats() {
|
||||
return boats.toArray(new Boat[boats.size()]);
|
||||
}
|
||||
/**
|
||||
* Prints the list of boats competing in the race
|
||||
*/
|
||||
public void displayStartingBoats() {
|
||||
int numberOfBoats = this.getNumberOfBoats();
|
||||
Boat[] boats = this.getBoats();
|
||||
|
||||
/*
|
||||
Prints the order in which the boats finished
|
||||
*/
|
||||
public void displayFinishingOrder() {
|
||||
int numberOfBoats = this.getNumberOfBoats();
|
||||
Boat[] boats = this.getFinishedBoats();
|
||||
System.out.println("######################");
|
||||
System.out.println("# Competing Boats ");
|
||||
System.out.println("######################");
|
||||
|
||||
System.out.println("\n\n");
|
||||
System.out.println("--- Finishing Order ---");
|
||||
for (int i = 0; i < numberOfBoats; i++) {
|
||||
String velocityKnots = String.format("%1.2f", boats[i].getVelocity() * 1.943844492);
|
||||
|
||||
for (int i = 0; i < Array.getLength(boats); i++) {
|
||||
System.out.println("#" + Integer.toString(i + 1) + " - " + boats[i].getTeamName());
|
||||
}
|
||||
}
|
||||
System.out.println(boats[i].getTeamName() + " Velocity: " + velocityKnots);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Prints the list of boats competing in the race
|
||||
*/
|
||||
public void displayStartingBoats() {
|
||||
int numberOfBoats = this.getNumberOfBoats();
|
||||
Boat[] boats = this.getBoats();
|
||||
/**
|
||||
* Adds a leg to the race
|
||||
*
|
||||
* @param leg, the leg to add to the race
|
||||
*/
|
||||
public void addLeg(Leg leg) {
|
||||
this.legs.add(leg);
|
||||
}
|
||||
|
||||
System.out.println("######################");
|
||||
System.out.println("# Competing Boats ");
|
||||
System.out.println("######################");
|
||||
/**
|
||||
* Gets legs array
|
||||
*
|
||||
* @return an array of legs
|
||||
*/
|
||||
public ArrayList<Leg> getLegs() {
|
||||
return this.legs;
|
||||
}
|
||||
|
||||
for (int i = 0; i < numberOfBoats; i++) {
|
||||
String velocityKnots = String.format("%1.2f", boats[i].getVelocity() * 1.943844492);
|
||||
/**
|
||||
* Sets time scale
|
||||
*
|
||||
* @param timeScale
|
||||
*/
|
||||
public void setTimeScale(double timeScale) {
|
||||
this.timeScale = timeScale;
|
||||
}
|
||||
|
||||
System.out.println(boats[i].getTeamName() + " Velocity: " + velocityKnots);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Temporary method used to generated all the events.
|
||||
*/
|
||||
private void generateEvents() {
|
||||
|
||||
/*
|
||||
Adds a leg to the race
|
||||
//calculate the time for every boat passes each leg, and create an event
|
||||
for (Boat boat : this.boats) {
|
||||
long totalDistance = 0;
|
||||
for (Leg leg : this.legs) {
|
||||
long time = (long) (1000 * totalDistance / boat.getVelocity());
|
||||
Event event = new Event(time, boat, leg);
|
||||
events.add(event);
|
||||
totalDistance += leg.getDistance();
|
||||
|
||||
@param leg, the leg to add to the race
|
||||
*/
|
||||
public void addLeg(Leg leg) {
|
||||
this.legs.add(leg);
|
||||
}
|
||||
// If finishing leg, add another event for when the boat finishes the race
|
||||
if (leg.getIsFinishingLeg()) {
|
||||
time = (long) (1000 * totalDistance / boat.getVelocity());
|
||||
event = new Event(time, boat, leg, true);
|
||||
events.add(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets legs array
|
||||
*
|
||||
* @return an array of legs
|
||||
*/
|
||||
public ArrayList<Leg> getLegs() {
|
||||
return this.legs;
|
||||
}
|
||||
/**
|
||||
* Note: this function is useless so far
|
||||
* Calculates how far a boat has travelled in meter
|
||||
*
|
||||
* @param velocity the velocity of boat
|
||||
* @return a float number of distance the boat has been travelled
|
||||
*/
|
||||
public float getDistanceTravelled(long velocity) {
|
||||
long timeDiff = System.currentTimeMillis() - this.startTime;
|
||||
long timeElapse = (long) (timeDiff / 1000 * this.timeScale);
|
||||
return timeElapse * velocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets time scale
|
||||
* @param timeScale
|
||||
*/
|
||||
public void setTimeScale(double timeScale) {
|
||||
this.timeScale = timeScale;
|
||||
}
|
||||
/**
|
||||
* Iterate over events in the race and print the
|
||||
* event string for each event
|
||||
*/
|
||||
public void iterateEvents() {
|
||||
// iterates all events. ends when no event in events.
|
||||
while (!events.isEmpty()) {
|
||||
Event peekEvent = events.peek();
|
||||
long currentTime = (long) ((System.currentTimeMillis() - this.startTime) * this.timeScale);
|
||||
|
||||
/**
|
||||
* Temporary method used to generated all the events.
|
||||
*/
|
||||
private void generateEvents() {
|
||||
if (currentTime > peekEvent.getTime()) {
|
||||
// pull out the event
|
||||
Event nextEvent = events.poll();
|
||||
|
||||
//calculate the time for every boat passes each leg, and create an event
|
||||
for (Boat boat : this.boats) {
|
||||
long totalDistance = 0;
|
||||
for (Leg leg : this.legs) {
|
||||
long time = (long) (1000 * totalDistance / boat.getVelocity());
|
||||
Event event = new Event(time, boat, leg);
|
||||
events.add(event);
|
||||
totalDistance += leg.getDistance();
|
||||
// I just simply print it out for testing
|
||||
System.out.println(nextEvent.getEventString());
|
||||
nextEvent.addBoatToMarker();
|
||||
|
||||
// If finishing leg, add another event for when the boat finishes the race
|
||||
if (leg.getIsFinishingLeg()){
|
||||
time = (long) (1000 * totalDistance / boat.getVelocity());
|
||||
event = new Event(time, boat, leg, true);
|
||||
events.add(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nextEvent.getIsFinishingEvent()) {
|
||||
this.finishingOrder.add(nextEvent.getBoat());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this function is useless so far
|
||||
* Calculates how far a boat has travelled in meter
|
||||
*
|
||||
* @param velocity the velocity of boat
|
||||
* @return a float number of distance the boat has been travelled
|
||||
*/
|
||||
public float getDistanceTravelled(long velocity) {
|
||||
long timeDiff = System.currentTimeMillis() - this.startTime;
|
||||
long timeElapse = (long) (timeDiff / 1000 * this.timeScale);
|
||||
return timeElapse * velocity;
|
||||
}
|
||||
// Wait for 100ms to slow down the while loop
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (java.lang.InterruptedException e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over events in the race and print the
|
||||
* event string for each event
|
||||
*/
|
||||
public void iterateEvents() {
|
||||
// iterates all events. ends when no event in events.
|
||||
while (!events.isEmpty()) {
|
||||
Event peekEvent = events.peek();
|
||||
long currentTime = (long) ((System.currentTimeMillis() - this.startTime) * this.timeScale);
|
||||
/**
|
||||
* Start the race and print each marker with the order
|
||||
* in which the boats passed that marker
|
||||
*/
|
||||
public void startRace() {
|
||||
// record start time.
|
||||
generateEvents();
|
||||
this.startTime = System.currentTimeMillis();
|
||||
iterateEvents();
|
||||
}
|
||||
|
||||
if (currentTime > peekEvent.getTime()) {
|
||||
// pull out the event
|
||||
Event nextEvent = events.poll();
|
||||
/**
|
||||
* Print the order in which the boats passed each marker
|
||||
*/
|
||||
public void showRaceMarkerResults() {
|
||||
for (Leg leg : this.legs) {
|
||||
Boat[] boats = leg.getMarker().getBoats();
|
||||
|
||||
// I just simply print it out for testing
|
||||
System.out.println(nextEvent.getEventString());
|
||||
nextEvent.addBoatToMarker();
|
||||
System.out.println("--- " + leg.getMarkerLabel() + " ---");
|
||||
|
||||
if (nextEvent.getIsFinishingEvent()){
|
||||
this.finishingOrder.add(nextEvent.getBoat());
|
||||
}
|
||||
}
|
||||
// Print the order in which the boats passed the marker
|
||||
for (int i = 0; i < this.getNumberOfBoats(); i++) {
|
||||
System.out.println("#" + Integer.toString(i + 1) + " - " + boats[i].getTeamName());
|
||||
}
|
||||
|
||||
// Wait for 100ms to slow down the while loop
|
||||
try{
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch(java.lang.InterruptedException e){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Start the race and print each marker with the order
|
||||
in which the boats passed that marker
|
||||
*/
|
||||
public void startRace() {
|
||||
// record start time.
|
||||
generateEvents();
|
||||
this.startTime = System.currentTimeMillis();
|
||||
iterateEvents();
|
||||
}
|
||||
|
||||
/*
|
||||
Print the order in which the boats passed each marker
|
||||
*/
|
||||
public void showRaceMarkerResults(){
|
||||
for (Leg leg : this.legs) {
|
||||
Boat[] boats = leg.getMarker().getBoats();
|
||||
|
||||
System.out.println("--- " + leg.getMarkerLabel() + " ---");
|
||||
|
||||
// Print the order in which the boats passed the marker
|
||||
for (int i = 0; i < this.getNumberOfBoats(); i++) {
|
||||
System.out.println("#" + Integer.toString(i + 1) + " - " + boats[i].getTeamName());
|
||||
}
|
||||
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user