Given the following class: public abstract class Cake { protected String name; protected double rate; public Cake (String n, double r) { name = n; rate = r; } public abstract double calcPrice(); public String toString() { return name + “\ “ \t” + rate; } } a) Based on class Cake and the following table, define TWO (2) subclasses named as orderCake and readymadeCake.
orderCake
readymadeCake
Additional Additional attribute
weight(kg)
quantity
Price calculation
rate*weight
rate*quantity rate*quantity
b) By using classes definition from a), write an application program that will: i) declare an an array of 20 cake 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.
OBJECT ORIENTED PROGRAMMING 2
CSC 238
Given the following cyclingGlass and swimmingGlass subclass are inherited from sportVissionShoppe superclass Superclass : sportVisionShoppe Attributes: String custOrderNo String custOrderDate float depositPymt
// customer order number // date of order
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() public String toString()
//method to calculate the price // method to display the data members
Details of charges are shown in table 4.1 below: Glass Type
Method: public double calCharges() public String toString()
//method to calculate the price // method to display the data members
OBJECT ORIENTED PROGRAMMING
CSC 238
Details of charges are shown in table 4.2 below: Style and Discount Glass Type
Price Retro
Warrior
Modern
Anti-Fogging google
RM 150.00
7%
30%
10%
Short-sighted google
RM 250.00
5%
20%
7%
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. Super class : Bank public class Bank { String accNo; //customer account number with Bank String custName; //customer name int custGender; //customer gender – 1 = Male, 2 =Female String custJob; //customer job position souble curBal; //customer balance in the bank account public String toString(); public abstract double calcBalance();
Subclass : Saving public class Saving { double savRate; //percent interest rate per year }
Subclass : Current public class Current{ boolean fixedDep; double curRate;
//whether the customer keeps the fixed // deposit with the bank of not //percent interest rate per year
}
The above classes show that Bank can have two different types of account which are
OBJECT ORIENTED PROGRAMMING
CSC 238
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. a) b)
c)
Write a method of calcBalance() for both subclasses. (5 marks) Search a customer based on the account number entered then display detail information of him/her. If the customer account number is not found, display an appropriate message. (5 marks) Count how many customers that have the current account with the bank and the total balance. (5 marks)
Thank you for interesting in our services. We are a non-profit group that run this website to share documents. We need your help to maintenance this website.