Display list of finishers after race ends.

main
Connor Taylor-Brown 9 years ago
parent 2db4beadcb
commit b1f588248b

@ -1,33 +1,26 @@
package seng302;
import java.util.ArrayList;
import java.util.LinkedList;
public class App
{
public static void main( String[] args )
{
LinkedList<Integer> test = new LinkedList<>();
test.add(5);
test.add(1, 8);
Boat boat1 = new Boat("ORACLE TEAM USA", 10);
Boat boat2 = new Boat("Artemis Racing", 8);
Boat boat3 = new Boat("Emirates Team New Zealand", 12);
Boat boat4 = new Boat("Groupama Team France", 11);
Boat boat5 = new Boat("Land Rover BAR", 10);
Boat boat6 = new Boat("SoftBank Team Japan", 9);
RaceMarker mark1 = new RaceMarker("Start", 0, 0, 59);
RaceMarker mark2 = new RaceMarker("Mark", 72, 72, 50);
RaceMarker mark3 = new RaceMarker("Leeward Gate", 193, 126, 158);
RaceMarker mark4 = new RaceMarker("Windward Gate", 373, 41, 0);
RaceMarker mark5 = new RaceMarker("Leeward Gate", 553, 126, 158);
RaceMarker mark6 = new RaceMarker("Finish", 607, 95, 203);
Boat[] boats = {
new Boat("ORACLE TEAM USA", 10),
new Boat("Artemis Racing", 8),
new Boat("Emirates Team New Zealand", 12),
new Boat("Groupama Team France", 11),
new Boat("Land Rover BAR", 10),
new Boat("SoftBank Team Japan", 9)
};
Boat[] boats = {boat1, boat2, boat3, boat4, boat5, boat6};
RaceMarker[] marks = {mark1, mark2, mark3, mark4, mark5, mark6};
RaceMarker[] marks = {
new RaceMarker("Start", 0, 0, 59),
new RaceMarker("Mark", 72, 72, 50),
new RaceMarker("Leeward Gate", 193, 126, 158),
new RaceMarker("Windward Gate", 373, 41, 0),
new RaceMarker("Leeward Gate", 553, 126, 158),
new RaceMarker("Finish", 607, 95, 203)
};
Race race = new ConstantVelocityRace(boats, marks);
race.simulateRace();

@ -1,9 +1,5 @@
package seng302;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
/**
* Created by fwy13 on 3/03/17.
*/
@ -27,11 +23,19 @@ public class Event {
}
public double calculateHeading(){
//to be changed to cooridinates when used to match reality.
//to be changed to coordinates when used to match reality.
double thetaHat = Math.atan2((goalMarker.getLatitude() - raceMarker.getLatitude()), (goalMarker.getLongitude() - raceMarker.getLongitude()));
return thetaHat >= 0 ? Math.toDegrees(thetaHat): Math.toDegrees(thetaHat + 2 * Math.PI);
}
public RaceMarker getRaceMarker() {
return raceMarker;
}
public Boat getBoat() {
return boat;
}
public void setTime(int time){
this.time = time;
}

@ -10,6 +10,7 @@ public class Race {
Boat[] boats;
RaceMarker[] marks;
LinkedList<Event> events = new LinkedList<Event>();
Timer timer = new Timer();
public Race(Boat[] boats, RaceMarker[] marks){
this.boats = boats;
@ -18,24 +19,43 @@ public class Race {
public void simulateRace(){
//show the boats participating.
System.out.println("Boats Participating.");
System.out.println("Boats Participating:");
System.out.println("====================");
for (int i = 0; i < boats.length; i ++){
System.out.println(i + 1 + ". " + boats[i].getName() + ", Speed: " + Math.round(boats[i].getVelocity() * 1.94384) + "kn");
}
System.out.println("\nRace Events");
System.out.println("====================");
System.out.println("\nRace Events:");
System.out.println("============");
//show all the events that happen in the race
for (Event event: events) {
Timer timer = new Timer();
timer.schedule(new TimerTask(){
@Override
public void run(){
System.out.println(event);
}
}, event.getTime() * 100);
}, event.getTime() * 1000);
}
/*
As the event readout is scheduled, the list of finishers must be
displayed afterwards, without the use of threading.
*/
timer.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("\nFinish:");
System.out.println("=======");
// Print the list of finishers with their placing and time
int place = 1;
for(Event event: events) {
if(event.getRaceMarker().getName().equals("Finish")) {
System.out.println(place + ". " + event.getBoat() + " (" + event.getTime() + "s)");
place++;
}
}
}
}, (events.getLast().getTime() + 1) * 1000);
}
}

@ -16,6 +16,10 @@ public class RaceMarker {
this.longitude = longitude;
}
public String getName() {
return name;
}
public double getDistance() {
return distance;
}

Loading…
Cancel
Save