Learning Profile for Assignment #2 Question #10
Name: Mo Khan
Student ID: 3431709
- Problem Statement A train timetable for a train travelling between Vancouver and Toronto is given below.
| Station | Arrival | Departure | Day |
|---|---|---|---|
| Vancouver | 20:30 | 1 | |
| Kamloops | 06:00 | 06:35 | 2 |
| Jasper | 16:00 | 17:30 | 2 |
| Edmonton | 23:00 | 23:59 | 2 |
| Saskatchewan | 08:00 | 08:25 | 3 |
| Winnipeg | 20:45 | 22:30 | 3 |
| Sioux Lookout | 05:02 | 05:42 | 4 |
| Hornepayne | 15:35 | 16:10 | 4 |
| Capreol | 00:18 | 00:48 | 5 |
| Toronto | 09:30 | 5 |
Store the information from each row of the table in an object.
Then, arrange the objects in an ArrayList structure.
Your program should now take the following commands in a continuous loop:
-
Show - shows the full table
-
Delay
<station><minutes>- the arrival of the train is delayed by<minutes>at station<station>; that is, add the delay to the corresponding station entry. For example,Delay Edmonton 30implies that the train would arrive 30 minutes later than the expected time of arrival in Edmonton. The new entry would beEdmonton 23:30 00:29 3. All stations following Edmonton will also update their arrival and departure by +30 minutes, and consequently the day of arrival and departures as well. The result of thisDelaycommadn is shown below:Station Arrival Departure Day Vancouver 20:30 1 Kamloops 06:00 06:35 2 Jasper 16:00 17:30 2 Edmonton 23:30 00:29 3 Saskatchewan 08:30 08:55 3 Winnipeg 21:15 23:00 3 Sioux Lookout 05:32 06:12 4 Hornepayne 16:05 16:40 4 Capreol 00:48 01:18 5 Toronto 10:00 5 -
Quit - stop the program from accepting any more commands.
-
Description of the Code There are two classes.
TrainTimeTableis responsible for add a delay in minutes starting for a specific station.Stationis responsible for managing the arrival and departure time to/from a specific train station.
When a delay is added to the time table the code will add the delay to the station, then to each station after it.
It would have been easier to represent dates as a unix timestamp, which is the number of seconds since the UNIX epoch. The Java Date class prefers to use millisecond precision.
All dates are represented using the UTC timezone.
I chose to add a method/constructor overloads to make the API of each of the classes easier to unit test. This also helped the class design to better adhere to the open/closed principle.
-
Errors and Warnings
-
When an unknown command is entered, the prompt is shown again.
```bash
モ mvn package
モ java -cp target/assignment2*.jar ca.mokhan.comp268.App 10
=== Question 10 ===
Enter command (Show, Delay, Quit):
invalid
Unknown command
Enter command (Show, Delay, Quit):
```
- When an unknown city is entered, an error is displayed.
```bash
モ mvn package
モ java -cp target/assignment2*.jar ca.mokhan.comp268.App 10
=== Question 10 ===
Enter command (Show, Delay, Quit):
Delay Calgary 25
`Calgary` is not on the schedule
Enter command (Show, Delay, Quit):
```
- When a non-numeric value is entered for minutes, an error is displayed.
```bash
java -cp target/assignment2*.jar ca.mokhan.comp268.App 10
=== Question 10 ===
Enter command (Show, Delay, Quit):
Delay Edmonton blah
Invalid minutes entered
Enter command (Show, Delay, Quit):
```
- When a delay of greater than 48 hours is entered, an error is displayed.
```bash
java -cp target/assignment2*.jar ca.mokhan.comp268.App 10
=== Question 10 ===
Enter command (Show, Delay, Quit):
Delay Edmonton 9999
Invalid minutes entered
Enter command (Show, Delay, Quit):
```
- Sample Input and Output
-
Below is an example run of the program.
$ mvn package $ java -cp target/assignment2*.jar ca.mokhan.comp268.App 10 === Question 10 === Enter command (Show, Delay, Quit): Show Station | Arrival | Departure | Day Vancouver | - | 20:30 | 1 Kamloops | 06:00 | 06:35 | 2 Jasper | 16:00 | 17:30 | 2 Edmonton | 23:00 | 23:59 | 2 Saskatchewan | 08:00 | 08:25 | 3 Winnipeg | 20:45 | 22:30 | 3 Sioux Lookout | 05:02 | 05:42 | 4 Hornepayne | 15:35 | 16:10 | 4 Capreol | 00:18 | 00:48 | 5 Toronto | 09:30 | - | 5 Enter command (Show, Delay, Quit): Delay Edmonton 30 Enter command (Show, Delay, Quit): Show Station | Arrival | Departure | Day Vancouver | - | 20:30 | 1 Kamloops | 06:00 | 06:35 | 2 Jasper | 16:00 | 17:30 | 2 Edmonton | 23:30 | 00:29 | 3 Saskatchewan | 08:30 | 08:55 | 3 Winnipeg | 21:15 | 23:00 | 3 Sioux Lookout | 05:32 | 06:12 | 4 Hornepayne | 16:05 | 16:40 | 4 Capreol | 00:48 | 01:18 | 5 Toronto | 10:00 | - | 5 Enter command (Show, Delay, Quit): quit
- Discussion
Saskatchewan is not a city.