Professional Documents
Culture Documents
Object Oriented Programming Lab Exercise: Polymorphism: Ordercake Readymadecake
Object Oriented Programming Lab Exercise: Polymorphism: Ordercake Readymadecake
a) Based on class Cake and the following table, define TWO (2) subclasses named as
orderCake and readymadeCake.
orderCake readymadeCake
b) By using classes definition from a), write an application program that will:
i) declare an array of 20 cake objects;
ii) input data for cake objects and store them into the array;
iii) display the total price for all types of cakes;
v) display the total price and the quantity sold for ready made cakes;
v) display the information for the cake that has been sold for the highest price.
Superclass : sportVisionShoppe
Attributes:
String custOrderNo // customer order number
String custOrderDate // date of order
float depositPymt
Abstract Method:
public abstract double calCharges() //method to calculate the price
Subclass : cyclingGlass
Attributes:
char type_glass // ‘T’ – Transition Glass, ‘P’ – Polarized glass, ‘I’ – Iridium glass
boolean uvProtection; // with UV protection extra RM 30 will be charge to the total price
Float depositPymt
Method:
public double calCharges() //method to calculate the price
public String toString() // method to display the data members
Transition RM 300.00
Polarized RM 350.00
Iridium RM 400.00
Table 4.1
Subclass : swimmingGlass
Attributes:
char Type; // ‘A’ – Anti-fogging google, ‘S’ – short-sighted googlr
String style; // “Retro”, “Warrior” or “Modern”
Method:
public double calCharges() //method to calculate the price
public String toString() // method to display the data members
Table 4.2
a) Write an abstract method of calCharges() to calculate the charges for both subclasses
b) Assume bellow coding being defined :
//consist of both subclasses objects
sportVisionShope[] S = new sportVisionShope[10]
Write a program to determine and display the number of customer who buy cycling and
swimming glass from the sportVisionShoppe
c) Write a program to calculate the total charges for all customers who bpught “Retro” goggle at
the sportVisionShoppe outlet.
Write a program to list the deposit paid by the customer who bought transition cycling glass from this
shop,
3 The following are the superclass Bank and its subclasses Saving and Current.
Subclass : Saving
public class Saving {
double savRate; //percent interest rate per year
Subclass : Current
public class Current{
boolean fixedDep; //whether the customer keeps the fixed
// deposit with the bank of not
double curRate; //percent interest rate per year
}
The above classes show that Bank can have two different types of account which are
Saving and Current account. The balance amount in the bank for each account is based
on the following calculation :
Saving :
Balance = current balance + (savRate * current balance)
Current :
Balance = current balance + (curRate * current balance)
If the customer has a fixed deposit with the bank, then the bank will charge RM150
for the service fee. The amount will be deducted automatically yearly.