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:
Generated
+1
-14
@@ -1,8 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="EntryPointsManager">
|
|
||||||
<entry_points version="2.0" />
|
|
||||||
</component>
|
|
||||||
<component name="MavenProjectsManager">
|
<component name="MavenProjectsManager">
|
||||||
<option name="originalFiles">
|
<option name="originalFiles">
|
||||||
<list>
|
<list>
|
||||||
@@ -10,17 +7,7 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
|
||||||
<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">
|
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
<component name="masterDetails">
|
<component name="masterDetails">
|
||||||
|
|||||||
@@ -1,11 +1,25 @@
|
|||||||
package seng302;
|
package seng302;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class App
|
public class App
|
||||||
{
|
{
|
||||||
public static void main( String[] args )
|
public static void main( String[] args )
|
||||||
{
|
{
|
||||||
int factor = 200; // Scale 5 min to 1 min
|
int timescale = 0; // Scale 5 min to 1 min, 1min = 200 5 min = 1000
|
||||||
if(args.length > 0 && args[0].equals("-5")) factor = 1000; // 1:1 scale
|
|
||||||
|
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 = {
|
Boat[] boats = {
|
||||||
new Boat("ORACLE TEAM USA", 11),
|
new Boat("ORACLE TEAM USA", 11),
|
||||||
@@ -25,7 +39,7 @@ public class App
|
|||||||
new RaceMarker("Finish", 3035, 475, 1015)
|
new RaceMarker("Finish", 3035, 475, 1015)
|
||||||
};
|
};
|
||||||
|
|
||||||
Race race = new ConstantVelocityRace(boats, marks, factor);
|
Race race = new ConstantVelocityRace(boats, marks, timescale);
|
||||||
race.simulateRace();
|
race.simulateRace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import java.util.Collections;
|
|||||||
* Created by cbt24 on 6/03/17.
|
* Created by cbt24 on 6/03/17.
|
||||||
*/
|
*/
|
||||||
public class ConstantVelocityRace extends Race {
|
public class ConstantVelocityRace extends Race {
|
||||||
public ConstantVelocityRace(Boat[] boats, RaceMarker[] marks, int factor) {
|
public ConstantVelocityRace(Boat[] boats, RaceMarker[] marks, int timescale) {
|
||||||
super(boats, marks, factor);
|
super(boats, marks, timescale);
|
||||||
generateRace();
|
generateRace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,6 @@ public class Event {
|
|||||||
return boat;
|
return boat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTime(int time){
|
|
||||||
this.time = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTime(){
|
public int getTime(){
|
||||||
return this.time;
|
return this.time;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,15 +9,16 @@ import java.util.*;
|
|||||||
public class Race {
|
public class Race {
|
||||||
Boat[] boats;
|
Boat[] boats;
|
||||||
RaceMarker[] marks;
|
RaceMarker[] marks;
|
||||||
int factor;
|
int timescale = 1000;
|
||||||
|
|
||||||
LinkedList<Event> events = new LinkedList<Event>();
|
LinkedList<Event> events = new LinkedList<Event>();
|
||||||
Timer timer = new Timer();
|
Timer timer = new Timer();
|
||||||
|
|
||||||
public Race(Boat[] boats, RaceMarker[] marks, int factor) {
|
|
||||||
|
public Race(Boat[] boats, RaceMarker[] marks, int timescale) {
|
||||||
this.boats = boats;
|
this.boats = boats;
|
||||||
this.marks = marks;
|
this.marks = marks;
|
||||||
this.factor = factor;
|
this.timescale = timescale;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void simulateRace(){
|
public void simulateRace(){
|
||||||
@@ -37,7 +38,7 @@ public class Race {
|
|||||||
public void run(){
|
public void run(){
|
||||||
System.out.println(event);
|
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.
|
* Created by cbt24 on 6/03/17.
|
||||||
*/
|
*/
|
||||||
public class RandomisedRace extends Race {
|
public class RandomisedRace extends Race {
|
||||||
public RandomisedRace(Boat[] boats, RaceMarker[] marks, int factor) {
|
public RandomisedRace(Boat[] boats, RaceMarker[] marks, int timescale) {
|
||||||
super(boats, marks, factor);
|
super(boats, marks, timescale);
|
||||||
generateRace();
|
generateRace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user