Professional Documents
Culture Documents
Week5-CS111-Lab5 - 1 - Monday
Week5-CS111-Lab5 - 1 - Monday
Programming Language 2
Computer Science Department
2022
Lab Objectives:
In this lab, a student will practice
Car BUS
- carSize: String; - numberOfSeats: int;
Write a Java program that demonstrate the above relationships. Your program must logically represent the
relationships. In your program, design and implement 3 classes, as shown in UML diagram given above in
the same package; then write a test application to demonstrate the classes capabilities.
• Abstract classes and methods are represented in italic. (Vehicle Class, printVehicleName() method,
and numberOfPassengers() method )
• printVehicleName() in method in each subclass should print the name of the subclass.
• carSize can be “small” or “ large”.
• numberOfPassengers() method for Car class returns 4 if carSize is “small” and 6 if carSize “large”.
For BUS class will returns (numberOfSeats-2).
Write a Java program that demonstrate the above relationships. In your program, design and implement 3
classes, as shown in UML diagram given above in the same package; then write a test application to
demonstrate the classes capabilities. Consider the following points:
In the super class:
• The method generateID() returns a random integer number between 1000-9999
• The constructor should call generateID() to set the id variable
In subclasses:
• Set the default value of monthlyCharge to 1000 SAR for VipMembership and 500 SAR for
BASIC_MEMBERSHIP
• The VipMembership constructor should set the value of numOfMonths to 12 months.
• Method getTotalCharge() returns the total charge as :
total charge = monthly charge * numOfMonths
However, In BASIC_MEMBERSHIP class if the member has access to the swimming pool do the
following:
total charge = monthly charge * numOfMonths +200
• toString() method should prints the following :
o Membership type: VIP or Basic
o Member name and ID
o Total charge
In test class:
4. Create a VipMembership object.
5. Create Two objects of BASIC_MEMBERSHIP one with a swimming pool access and one without.
6. Print the information for each object.