mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Added method to calculate distance travelled given velocity
- added getDistanceTravelled(velocity) to calculate how far a boat has travelled - added startTime for calculating time elapse between start point and enquiry point #story[6]
This commit is contained in:
@@ -15,7 +15,6 @@ public class App
|
|||||||
for (Map<String, Object> team : teams) {
|
for (Map<String, Object> team : teams) {
|
||||||
boatNames.add((String) team.get("team-name"));
|
boatNames.add((String) team.get("team-name"));
|
||||||
}
|
}
|
||||||
System.out.println(boatNames.toString());
|
|
||||||
|
|
||||||
// Shuffle team names
|
// Shuffle team names
|
||||||
long seed = System.nanoTime();
|
long seed = System.nanoTime();
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ public class Race {
|
|||||||
private ArrayList<Boat> boats;
|
private ArrayList<Boat> boats;
|
||||||
private ArrayList<Leg> legs;
|
private ArrayList<Leg> legs;
|
||||||
private int numberOfBoats = 0;
|
private int numberOfBoats = 0;
|
||||||
|
private long startTime = 0;
|
||||||
|
private int timeScale = 1;
|
||||||
|
|
||||||
public Race(){
|
public Race(){
|
||||||
boats = new ArrayList<Boat>();
|
boats = new ArrayList<Boat>();
|
||||||
@@ -103,11 +105,33 @@ public class Race {
|
|||||||
this.legs.add(leg);
|
this.legs.add(leg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets legs array
|
||||||
|
* @return an array of legs
|
||||||
|
*/
|
||||||
|
public ArrayList<Leg> getLegs() {
|
||||||
|
return this.legs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 = timeDiff / 1000 * this.timeScale;
|
||||||
|
return timeElapse * velocity;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Start the race and print each marker with the order
|
Start the race and print each marker with the order
|
||||||
in which the boats passed that marker
|
in which the boats passed that marker
|
||||||
*/
|
*/
|
||||||
public void startRace(){
|
public void startRace(){
|
||||||
|
// record start time.
|
||||||
|
this.startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
for (Leg leg : this.legs.toArray(new Leg[legs.size()])){
|
for (Leg leg : this.legs.toArray(new Leg[legs.size()])){
|
||||||
Boat[] boats = this.getShuffledBoats();
|
Boat[] boats = this.getShuffledBoats();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user