summaryrefslogtreecommitdiff
path: root/src/Q10/README.md
blob: 7706fa659ed7d33d1af2e1c143c8b1c7cb4cfd1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Learning Profile for Assignment #2 Question #10

## Name: Mo Khan

### Student ID: 3431709

1. 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:
  1. Show - shows the full table
  1. 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 30` implies that the train would arrive
     30 minutes later than the expected time of arrival in Edmonton. The new
     entry would be `Edmonton 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 this
     `Delay` commadn 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 |

  1. Quit - stop the program from accepting any more commands.

1. Description of the Code
  There are two classes. `TrainTimeTable` is responsible for add a delay in
  minutes starting for a specific station. `Station` is 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.

1. Errors and Warnings

  1. 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):
    ```

  1. 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):
    ```

  1. 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):
    ```

  1. 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):
    ```

1. Sample Input and Output

  * Below is an example run of the program.

    ```bash
    $ 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
    ```

1. Discussion