summaryrefslogtreecommitdiff
path: root/src/Q10/TrainTimeTable.java
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2019-08-05 18:06:05 -0600
committermo khan <mo@mokhan.ca>2019-08-05 18:06:05 -0600
commit4bb8e0f13ef79ddb3f625bf899bb57f3d7c3754e (patch)
tree903fcac2d25bcdeb95f5c6bbe02852dba58913b3 /src/Q10/TrainTimeTable.java
parentfc18b379b9a4aa618d7b5c6d5c4fd74acfe03370 (diff)
concat tokens back into city name
Diffstat (limited to 'src/Q10/TrainTimeTable.java')
-rw-r--r--src/Q10/TrainTimeTable.java43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/Q10/TrainTimeTable.java b/src/Q10/TrainTimeTable.java
index b79f10e..5883983 100644
--- a/src/Q10/TrainTimeTable.java
+++ b/src/Q10/TrainTimeTable.java
@@ -15,7 +15,11 @@ public class TrainTimeTable {
}
public void delay(String city, int minutes) {
+ System.out.println();
+ System.out.println(city);
System.out.println(String.format("Delay %s by %d minutes", city, minutes));
+ System.out.println();
+
Station station = stationIn(city);
if (station != null) station.delayBy(minutes);
}
@@ -42,22 +46,23 @@ public class TrainTimeTable {
public static void main(String[] args) {
System.out.println("=== Question 10 ===");
- LinkedList<Station> stations = new LinkedList<Station>();
- stations.add(new Station("Vancouver", new Date(), new Date(), 1));
- stations.add(new Station("Kamloops", new Date(), new Date(), 2));
- stations.add(new Station("Jasper", new Date(), new Date(), 2));
- stations.add(new Station("Edmonton", new Date(), new Date(), 2));
- stations.add(new Station("Saskatchewan", new Date(), new Date(), 3));
- stations.add(new Station("Winnipeg", new Date(), new Date(), 3));
- stations.add(new Station("Sioux Lookout", new Date(), new Date(), 4));
- stations.add(new Station("Hornepayne", new Date(), new Date(), 4));
- stations.add(new Station("Capreol", new Date(), new Date(), 5));
- stations.add(new Station("Toronto", new Date(), new Date(), 5));
+ LinkedList<Station> stations =
+ new LinkedList<Station>(
+ Arrays.asList(
+ new Station("Vancouver", null, new Date(1546374600000L), 1),
+ new Station("Kamloops", new Date(1546408800000L), new Date(1546410900000L), 2),
+ new Station("Jasper", new Date(1546444800000L), new Date(1546450200000L), 2),
+ new Station("Edmonton", new Date(1546470000000L), new Date(1546473540000L), 2),
+ new Station("Saskatchewan", new Date(1546502400000L), new Date(1546503900000L), 3),
+ new Station("Winnipeg", new Date(1546548300000L), new Date(1546554600000L), 3),
+ new Station("Sioux Lookout", new Date(1546578120000L), new Date(1546580520000L), 4),
+ new Station("Hornepayne", new Date(1546616100000L), new Date(1546618200000L), 4),
+ new Station("Capreol", new Date(1546647480000L), new Date(1546649280000L), 5),
+ new Station("Toronto", new Date(1546680600000L), null, 5)));
TrainTimeTable schedule = new TrainTimeTable(stations);
-
Scanner in = new Scanner(System.in);
- String selection = args.length > 0 ? args[0] : null;
+ String selection = null;
while (true) {
if (selection == null) {
@@ -73,11 +78,17 @@ public class TrainTimeTable {
} else {
String[] tokens = selection.split(" ");
- if (tokens.length == 3) {
- schedule.delay(tokens[1], Integer.parseInt(tokens[2]));
- } else {
+ if (tokens.length < 3) {
System.out.println("Could not parse command");
+ continue;
+ }
+
+ String city = "";
+ for (int i = 1; i < tokens.length - 1; i++) {
+ System.out.println(tokens[i]);
+ city += tokens[i];
}
+ schedule.delay(city, Integer.parseInt(tokens[tokens.length - 1]));
}
selection = null;