Commit ccbe674

mo khan <mo@mokhan.ca>
2019-08-05 21:32:24
complete very simple parsing
1 parent 63e281a
Changed files (1)
src/Q10/TrainTimeTable.java
@@ -14,7 +14,9 @@ public class TrainTimeTable {
     this.schedule = schedule;
   }
 
-  public void delay(String station, int minutes) {}
+  public void delay(String station, int minutes) {
+    System.out.println(String.format("Delay %s by %d minutes", station, minutes));
+  }
 
   public void displaySchedule() {
     this.displaySchedule(System.out);
@@ -53,7 +55,7 @@ public class TrainTimeTable {
       if (selection == null) {
         System.out.println();
         System.out.println("Enter command (Show, Delay, Quit):");
-        selection = in.next().toLowerCase();
+        selection = in.nextLine().toLowerCase();
       }
 
       if (selection.equals("quit")) return;
@@ -61,7 +63,13 @@ public class TrainTimeTable {
       if (selection.equals("show")) {
         schedule.displaySchedule(System.out);
       } else {
-        System.out.println("Delay schedule");
+        String[] tokens = selection.split(" ");
+
+        if (tokens.length == 3) {
+          schedule.delay(tokens[1], Integer.parseInt(tokens[2]));
+        } else {
+          System.out.println("Could not parse command");
+        }
       }
 
       selection = null;