/** * 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.text.*; import java.util.*; public class Station { private Date arrival; private Date departure; private int day; private String city; public Station(String city, Date arrival, Date departure, int day) { this.city = city; this.arrival = arrival; this.departure = departure; this.day = day; } public Date getArrivalDate() { return this.arrival; } public Date getDepartureDate() { return this.departure; } public int getDay() { return day; } public String getCity() { return this.city; } public void setArrivalDate(Date arrival) { this.arrival = arrival; } public void setCity(String city) { this.city = city; } public void setDay(int day) { this.day = day; } public void setDepartureDate(Date departure) { this.departure = departure; } public String getArrival() { return formatDate(this.arrival); } public String getDeparture() { return formatDate(this.departure); } public void delayBy(int minutes) { this.setArrivalDate(advanceDate(this.getArrivalDate(), minutes)); this.setDepartureDate(advanceDate(this.getDepartureDate(), minutes)); Calendar calendar = Calendar.getInstance(); calendar.setTime( this.getDepartureDate() != null ? this.getDepartureDate() : this.getArrivalDate()); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); this.setDay(calendar.get(Calendar.DAY_OF_MONTH)); } private String formatDate(Date date) { if (date == null) return "-"; DateFormat format = new SimpleDateFormat("HH:mm"); format.setTimeZone(TimeZone.getTimeZone("UTC")); return format.format(date); } private Date advanceDate(Date original, int minutes) { if (original == null) return null; return new Date(original.getTime() + (minutes * 60000)); } }