CSL-210: Object-Oriented Programming Lab
BS(CS)- Semester 02
(Spring 2021)
Lab06: Association and Aggregation
Designing and implementing Java programs that deal with:
1. Association and
2. Aggregation
Exercises
Exercise 1(a) (Time.java, Passenger.java, Flight.java, )
Association & Aggregation
Based On the class diagram given below, you are required to write complete program for
Flight's class, Time's class and Passenger's class with the concept of association and
aggregation.Functions information also been given in the table below . Program should
display information supplied to flight object.
Class Diagram
47
, CSL-210: Object-Oriented Programming Lab
BS(CS)- Semester 02
(Spring 2021)
Table of Methods for Flight Class
Method Description
addPassenger(Passenger) This method will add Passenger's object to vector
passengerList.
printInfo() This method will display all flight information namely ID
(Flight number), destination, departure time, arrival time
and number of passengers.
For Example:
Flight no : PK-303
Destination : Lahore
Departure : 8:10
Arrival : 9:00
Number of passenger :2
getHour() This method will return the value of attribute hour
getMinute() This method will return the value of attribute minute
48
, CSL-210: Object-Oriented Programming Lab
BS(CS)- Semester 02
(Spring 2021)
CLASS TIME :
package javaapplication64;
public class Time {
private int hour;
private int minute;
public int getHour() {
return hour;
}
public int getMinute() {
return minute;
}
public Time(int hour,int minute) {
this.hour=hour;
this.minute=minute;
}
}
49
BS(CS)- Semester 02
(Spring 2021)
Lab06: Association and Aggregation
Designing and implementing Java programs that deal with:
1. Association and
2. Aggregation
Exercises
Exercise 1(a) (Time.java, Passenger.java, Flight.java, )
Association & Aggregation
Based On the class diagram given below, you are required to write complete program for
Flight's class, Time's class and Passenger's class with the concept of association and
aggregation.Functions information also been given in the table below . Program should
display information supplied to flight object.
Class Diagram
47
, CSL-210: Object-Oriented Programming Lab
BS(CS)- Semester 02
(Spring 2021)
Table of Methods for Flight Class
Method Description
addPassenger(Passenger) This method will add Passenger's object to vector
passengerList.
printInfo() This method will display all flight information namely ID
(Flight number), destination, departure time, arrival time
and number of passengers.
For Example:
Flight no : PK-303
Destination : Lahore
Departure : 8:10
Arrival : 9:00
Number of passenger :2
getHour() This method will return the value of attribute hour
getMinute() This method will return the value of attribute minute
48
, CSL-210: Object-Oriented Programming Lab
BS(CS)- Semester 02
(Spring 2021)
CLASS TIME :
package javaapplication64;
public class Time {
private int hour;
private int minute;
public int getHour() {
return hour;
}
public int getMinute() {
return minute;
}
public Time(int hour,int minute) {
this.hour=hour;
this.minute=minute;
}
}
49