Completing the Time/Flight/Trip problem
public class Time {
// uses a 24 hour clock, the variables are hour and minute
// create a default constructor that sets the time to 1:00am
// create a constructor that sets the time to any hour/minute
// create accessor methods getHour and getMinute
// create a toString method that returns hh:mm with both as 2 digit numbers
// create a minutesUntil method that returns the number of minutes from this time to the parameter
}
public class Flight {
// the variables are start time and end time
// create a constructor that takes in 2 times to set the starting and ending time of a flight
// create a toString method that returns "Flight starting at hh:mm and ending at hh:mm"
// create the accessor methods getDepartureTime that returns the start time and getArrivalTime that returns the end time
}
public class Trip{
List<Flight> flights;
// the constructor instantiates the arraylist of flights
// the addFlight method takes in a Flight and adds it to the arraylist
// the toString method prints out all flights in the trip
// the getShortestLayover method returns the number of minutes of the shortest time between flights
// the getDuration method returns the number of minutes from the first takeoff until the final landing
}
public class Driver{
public static void main(String[] args){
Trip alaska = new Trip();
Time startTrip = new Time(08,30);
System.out.println("your trip will start at " + startTrip);
Flight chicago = new Flight(startTrip,new Time(10,15));
Flight denver = new Flight(new Time(10,40),new Time(1,45));
Flight seattle = new Flight(new Time(3,10),new Time(5,20));
System.out.println("The seattle flight starts at "+getDepartureTime()+" and arrives at "+getArrivalTime());
Flight juneau = new Flight(new Time(7,05),new Time(11,25));
System.out.println("final flight will be "+juneau);
alaska.addFlight(chicago);
alaska.addFlight(denver);
System.out.println("First leg "+alaska);
alaska.addFlight(seattle);
alaska.addFlight(juneau);
System.out.println("total trip "+alaska+" will take "+alaska.getDuration());
System.out.println("the shortest layover is "+alaska.getShortestLayover());
}
}