diff options
| author | mo khan <mo@mokhan.ca> | 2019-08-05 15:16:22 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2019-08-05 15:16:22 -0600 |
| commit | 63e281ac303cc78228ea1adbc3676c8a83ef8155 (patch) | |
| tree | ba390c996081028ab70373d0e12aa8a287e6a165 /src/Q10/TrainTimeTable.java | |
| parent | fc63be330c1589d9c79f527dd3f365fa5e80e2e7 (diff) | |
connect Q10 console application
Diffstat (limited to 'src/Q10/TrainTimeTable.java')
| -rw-r--r-- | src/Q10/TrainTimeTable.java | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/src/Q10/TrainTimeTable.java b/src/Q10/TrainTimeTable.java index c6477c4..a06012d 100644 --- a/src/Q10/TrainTimeTable.java +++ b/src/Q10/TrainTimeTable.java @@ -1,11 +1,70 @@ package Q10; +import java.io.*; import java.util.*; public class TrainTimeTable { private LinkedList<Station> schedule; + public TrainTimeTable() { + this(new LinkedList<Station>()); + } + + public TrainTimeTable(LinkedList<Station> schedule) { + this.schedule = schedule; + } + public void delay(String station, int minutes) {} - public void displaySchedule() {} + public void displaySchedule() { + this.displaySchedule(System.out); + } + + public void displaySchedule(PrintStream out) { + out.println("Station | Arrival | Departure | Day"); + + for (Station station : schedule) + out.println( + String.format( + "%s | %s | %s | %d", + station.getCity(), station.getArrival(), station.getDeparture(), station.getDay())); + } + + 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)); + + TrainTimeTable schedule = new TrainTimeTable(stations); + + Scanner in = new Scanner(System.in); + String selection = args.length > 0 ? args[0] : null; + + while (true) { + if (selection == null) { + System.out.println(); + System.out.println("Enter command (Show, Delay, Quit):"); + selection = in.next().toLowerCase(); + } + + if (selection.equals("quit")) return; + + if (selection.equals("show")) { + schedule.displaySchedule(System.out); + } else { + System.out.println("Delay schedule"); + } + + selection = null; + } + } } |
