import java.util.*;
import java.util.Calendar;
public class TrainTimeTable {
// Static method to print the date time of a Calendar object, note the get methods
public static void printCal(Calendar cal) {
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
System.out.printf("%4d/%02d/%02d %02d:%02d:%02d\n",
year, month+1, day, hour, minute, second);
}
public static void main(String[] args) {
//creating class objects
Station s1 = new Station("Station: Vancouver",null, null, 0);
Station s2 = new Station("Station: kamloops", null, null, 0);
Station s3 = new Station("Station: Jasper", null, null, 0);
Station s4 = new Station("Station: Edmonton", null, null, 0);
Station s5 = new Station("Station: Saskatoon", null, null, 0);
Station s6 = new Station("Station: Winnipeg", null, null, 0);
Station s7 = new Station("Station: Sioux Lookout", null, null, 0);
Station s8 = new Station("Station: Hornepayne", null, null, 0);
Station s9 = new Station("Station: Capreol", null, null, 0);
Station s10 = new Station("Station: Toronto", null, null, 0);
//creating arraylist
ArrayList schedule = new ArrayList();
schedule.add(s1);
schedule.add(s2);
schedule.add(s3);
schedule.add(s4);
schedule.add(s5);
schedule.add(s6);
schedule.add(s7);
schedule.add(s8);
schedule.add(s9);
schedule.add(s10);
for( Station st : schedule ) {
System.out.println( st );
}
// get an instance of Calendar, default is system data time
Calendar cal = Calendar.getInstance();
System.out.print("Current date time is: ");
printCal(cal);
// date time arithmetics
cal.add(Calendar.MINUTE, 30);
System.out.print("delay of station 10 by 30 min");
printCal(cal);
}//end main
}//end class
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
Saskatoon 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
This is what the time table starts at, I need to pick a station for example Saskatoon then make the train get there 30 minutes later then the original time and since the train will be getting there 30 minutes later it will be getting to all the next stations winnipeg, sioux lookout, hornepayne, capreol and toronto 30 minutes later as well. The only way I know how to do this is by manually changing the times one by one. The question wants me to use a method like this public void delay (String station, int minute) which will add the delay to a station and all the ones after. After that is done i need to display the updated time table. How can I go about doing this??? I have been stuck on this for over a week and am lost. thank you in advance for any help
I also have this code as well that I was using
// fix a date time
cal.set(2018, 01, 25, 00, 00, 00);
System.out.print("In vancouver: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 20, 30, 00);
System.out.print("Leaving Vancouver: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 6, 00, 00);
System.out.print("Arriving in kamloops: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 6, 35, 00);
System.out.print("leaving kamloops: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 16, 00, 00);
System.out.print("arriving in jasper: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 17, 30, 00);
System.out.print("leaving jasper: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 23, 00, 00);
System.out.print("arriving in edmonton: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 23, 59, 00);
System.out.print("leaving edmonton: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 8, 00, 00);
System.out.print("arriving in saskatoon: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 8, 25, 00);
System.out.print("leaving saskatoon: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 20, 45, 00);
System.out.print("arriving in winnipeg: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 22, 30, 00);
System.out.print("leaving winnipeg: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 5, 02, 00);
System.out.print("arriving in sioux lookout: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 5, 42, 00);
System.out.print("leaving sioux lookout: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 15, 35, 00);
System.out.print("arriving in hornepayne: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 16, 10, 00);
System.out.print("leaving hornepayne: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 00, 18, 00);
System.out.print("arriving in capreol: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 00, 48, 00);
System.out.print("leaving capreol: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 9, 30, 00);
System.out.print("arriving in toronto: ");
printCal(cal);
// fix a date time
cal.set(2018, 01, 25, 00, 00, 00);
System.out.print("no departures from here: ");
printCal(cal);
I want to be able to have the times in my time table instead of null. Sorry i know these are alot of problems but i am very stuck. Thank you again.