Implemented user input

- Changed it from launching the program with args setting to with Scanner.
- Changed field 'factor' to 'timescale' in Race class
#story [5] #pair[fwy13, cbt24]
This commit is contained in:
Fan-Wu Yang
2017-03-09 16:03:27 +13:00
parent 1a9cf5bdda
commit 2d777b8903
6 changed files with 28 additions and 30 deletions
+17 -3
View File
@@ -1,11 +1,25 @@
package seng302;
import java.util.Scanner;
public class App
{
public static void main( String[] args )
{
int factor = 200; // Scale 5 min to 1 min
if(args.length > 0 && args[0].equals("-5")) factor = 1000; // 1:1 scale
int timescale = 0; // Scale 5 min to 1 min, 1min = 200 5 min = 1000
Scanner sc = new Scanner(System.in);
while(timescale != 1 && timescale != 5) {
System.out.println("Enter whether you wish the race to last 1 or 5 minutes.");
String input = sc.nextLine();
try {
timescale = Integer.parseInt(input);
}catch (Exception e){
System.out.println("Please Enter a 1 or 5.");
}
}
timescale = timescale == 1 ? 200: 1000; //200ms = 1000ms if 1 minute elapse else 1000ms = 1000ms if 5 minutes
Boat[] boats = {
new Boat("ORACLE TEAM USA", 11),
@@ -25,7 +39,7 @@ public class App
new RaceMarker("Finish", 3035, 475, 1015)
};
Race race = new ConstantVelocityRace(boats, marks, factor);
Race race = new ConstantVelocityRace(boats, marks, timescale);
race.simulateRace();
}
}
@@ -6,8 +6,8 @@ import java.util.Collections;
* Created by cbt24 on 6/03/17.
*/
public class ConstantVelocityRace extends Race {
public ConstantVelocityRace(Boat[] boats, RaceMarker[] marks, int factor) {
super(boats, marks, factor);
public ConstantVelocityRace(Boat[] boats, RaceMarker[] marks, int timescale) {
super(boats, marks, timescale);
generateRace();
}
-4
View File
@@ -36,10 +36,6 @@ public class Event {
return boat;
}
public void setTime(int time){
this.time = time;
}
public int getTime(){
return this.time;
}
+6 -5
View File
@@ -9,15 +9,16 @@ import java.util.*;
public class Race {
Boat[] boats;
RaceMarker[] marks;
int factor;
int timescale = 1000;
LinkedList<Event> events = new LinkedList<Event>();
Timer timer = new Timer();
public Race(Boat[] boats, RaceMarker[] marks, int factor) {
public Race(Boat[] boats, RaceMarker[] marks, int timescale) {
this.boats = boats;
this.marks = marks;
this.factor = factor;
this.timescale = timescale;
}
public void simulateRace(){
@@ -37,7 +38,7 @@ public class Race {
public void run(){
System.out.println(event);
}
}, event.getTime() * factor);
}, event.getTime() * timescale);
}
/*
@@ -58,7 +59,7 @@ public class Race {
}
}
}
}, (events.getLast().getTime() + 1) * factor);
}, (events.getLast().getTime() + 1) * timescale);
}
}
+2 -2
View File
@@ -7,8 +7,8 @@ import java.util.Random;
* Created by cbt24 on 6/03/17.
*/
public class RandomisedRace extends Race {
public RandomisedRace(Boat[] boats, RaceMarker[] marks, int factor) {
super(boats, marks, factor);
public RandomisedRace(Boat[] boats, RaceMarker[] marks, int timescale) {
super(boats, marks, timescale);
generateRace();
}