Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

CS 111T - Lab

Programming Language 2
Computer Science Department
2022

Lab Objectives:
In this lab, a student will practice

• Create and use abstract classes


• Create and use abstract methods
Lab Exercise:
Vehicle
- colour: String;
- year: int;

// Full argument constructor


// Setters & Getters
+ printVehicleName():void
+ numberOfPassengers():int

Car BUS
- carSize: String; - numberOfSeats: int;

// Full argument constructor // Full argument constructor


// Setters & Getters // Setters & Getters

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.

Consider the following points:

• 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).

To test the classes:

1. Create Two objects, one of each subclass.


2. Call printVehicleName() for each object.
3. Call numberOfPassengers() for each object and print the result.
Assignment

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.

You might also like