flight information display system java
flight information display system java |
Based On the class diagram given below, you are required to write the complete program for Flight's class, Time's class and Passenger's class with the concept of association and aggregation. Function’s information has also been given in the table below. The program should display information supplied to the flight object
![]() |
flight information display system java |
Use the above classes
to create the objects in the FlightTester class and call methods
import java.util.Vector;
class Time {
private int hour;
private int minute;
Time(int hour, int minute) {
this.hour = hour;
this.minute = minute;
}
public int getHour() {
return this.hour;
}
public int getMinute() {
return this.minute;
}
}
class Passenger {
private String name;
private int age;
Passenger(String name, int age) {
this.name = name;
this.age = age;
}
}
class Flight {
String id;
String destination;
Time depart;
Time arrival;
Vector<Passenger> passengerList = new Vector<Passenger>();
Flight(String id, String destination, Time depart, Time arrival) {
this.id = id;
this.destination = destination;
this.depart = depart;
this.arrival = arrival;
}
void addPassenger(Passenger passenger) {
passengerList.add(passenger);
}
void printInfo() {
System.out.println("Flight No: " + this.id);
System.out.println("Destination: " + this.destination);
System.out.println("Departure: " + String.format("%02d", this.depart.getHour()) + ":"
+ String.format("%02d", this.depart.getMinute()));
System.out.println("Arrival: " + String.format("%02d", this.arrival.getHour()) + ":"
+ String.format("%02d", this.arrival.getMinute()));
System.out.println("Number of Passengers: " + this.passengerList.size());
}
}
public class FlightTester {
// main function
public static void main(String args[]) {
Time depart = new Time(22, 0);
Time arrival = new Time(01, 30);
Flight flight = new Flight("PK-Suk", "Istanbul", depart, arrival);
// passengers
flight.addPassenger(new Passenger("Mr. Faheem", 35));
flight.addPassenger(new Passenger("Mr. Muhammad Tayyab", 20));
flight.addPassenger(new Passenger("Mr. Amjad", 50));
flight.printInfo();
}
}