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]
main
Fan-Wu Yang 9 years ago
parent 1a9cf5bdda
commit 2d777b8903

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
@ -10,17 +7,7 @@
</list>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="masterDetails">

@ -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();
}

@ -36,10 +36,6 @@ public class Event {
return boat;
}
public void setTime(int time){
this.time = time;
}
public int getTime(){
return this.time;
}

@ -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);
}
}

@ -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();
}

Loading…
Cancel
Save