Commit c4eebac
Changed files (2)
src
src/Q10/README.md
@@ -169,3 +169,5 @@
```
1. Discussion
+
+ Saskatchewan is not a city.
src/Q10/TrainTimeTable.java
@@ -1,3 +1,11 @@
+/**
+ * Assignment 2, COMP268 Class: TrainTimeTable.java
+ *
+ * @description Provides a class to manage a train schedule.
+ * @author: mo khan Student ID: 3431709
+ * @date August 5, 2019
+ * @version 1.0
+ */
package Q10;
import java.io.*;
@@ -6,14 +14,22 @@ import java.util.*;
public class TrainTimeTable {
private LinkedList<Station> schedule;
+ /** The default constructor. */
public TrainTimeTable() {
this(new LinkedList<Station>());
}
+ /** An overloaded constructor to allow injections of each of the stations in the schedule. */
public TrainTimeTable(LinkedList<Station> schedule) {
this.schedule = schedule;
}
+ /**
+ * Adds a delay to the schedule starting at the given city.
+ *
+ * @param city The city where the delay begins.
+ * @param minutes The number of minutes to delay.
+ */
public void delay(String city, int minutes) {
Station station = stationIn(city);
if (station == null)
@@ -25,10 +41,15 @@ public class TrainTimeTable {
}
}
+ /** Prints the current schedule to standard out. */
public void displaySchedule() {
this.displaySchedule(System.out);
}
+ /**
+ * An overload of displaySchedule that accepts a PrintStream to write output to different
+ * printers.
+ */
public void displaySchedule(PrintStream out) {
out.println(String.format("%15s | %7s | %9s | %3s", "Station", "Arrival", "Departure", "Day"));
@@ -39,12 +60,21 @@ public class TrainTimeTable {
station.getCity(), station.getArrival(), station.getDeparture(), station.getDay()));
}
+ /**
+ * Returns the station that is in a city.
+ *
+ * @param city The city to search for
+ * @return the Station if found or null.
+ */
public Station stationIn(String city) {
for (Station station : this.schedule)
if (station.getCity().toLowerCase().equals(city.toLowerCase())) return station;
return null;
}
+ /**
+ * This is the main entry point to the console application.
+ */
public static void main(String[] args) {
System.out.println("=== Question 10 ===");
LinkedList<Station> stations =