Commit f59d4c7
Changed files (3)
src/Q10/Station.java
@@ -1,5 +1,6 @@
package Q10;
+import java.text.*;
import java.util.*;
public class Station {
@@ -27,18 +28,10 @@ public class Station {
return day;
}
- public String getArrival() {
- return this.getArrivalDate().toString();
- }
-
public String getCity() {
return this.city;
}
- public String getDeparture() {
- return getDepartureDate().toString();
- }
-
public void setArrivalDate(Date arrival) {
this.arrival = arrival;
}
@@ -54,4 +47,18 @@ public class Station {
public void setDepartureDate(Date departure) {
this.departure = departure;
}
+
+ public String getArrival() {
+ return formatDate(this.arrival);
+ }
+
+ public String getDeparture() {
+ return formatDate(this.departure);
+ }
+
+ private String formatDate(Date date) {
+ DateFormat format = new SimpleDateFormat("HH:mm");
+ format.setTimeZone(TimeZone.getTimeZone("UTC"));
+ return format.format(date);
+ }
}
src/Q10/StationTest.java
@@ -0,0 +1,30 @@
+package ca.mokhan.test;
+
+import Q10.*;
+import java.io.*;
+import java.text.*;
+import java.util.*;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class StationTest extends TestCase {
+ private Station subject;
+
+ public StationTest(String testName) {
+ super(testName);
+ this.subject = new Station("Edmonton", new Date(1546470000000L), new Date(1546473540000L), 2);
+ }
+
+ public static Test suite() {
+ return new TestSuite(StationTest.class);
+ }
+
+ public void test_getArrival() {
+ assertEquals("23:00", subject.getArrival());
+ }
+
+ public void test_getDeparture() {
+ assertEquals("23:59", subject.getDeparture());
+ }
+}
src/Q10/TrainTimeTable.java
@@ -33,6 +33,7 @@ public class TrainTimeTable {
}
public Station stationIn(String city) {
+ for (Station station : this.schedule) if (station.getCity() == city) return station;
return null;
}