Given The Following Super Class and Subclasses:: Exercise (Week 11) Inheritance and Polymorhism

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

EXERCISE (WEEK 11)

INHERITANCE AND POLYMORHISM

Given the following super class and subclasses:

public abstract class PearlService{


protected String custName; // customer name
protected String IC; // customer ic
protected String phoneNum; // customer phone number

//normal constructor
//setter methods
//getter methods

public abstract double calculateCharge();


public String toString();
}

public class MaidService extends PearlService{


private char dailyMaidPackage; // A or B
private int numOfDays;

//normal constructor
//setter method
//getter methods

public double calculateCharge(){ … }


}

public class LaundryService extends PearlService{


private String type; // Normal or Dry cleaning
private String clothType;
private int quantity;

//normal constructor
//setter method
//getter methods
public double calculateCharge(){ … }
}

a) Write the definition of normal constructor for both subclasses.


(4 marks)

b) Write the definition of method calculateCharge()for both subclasses based on the


following price:

Maid Service Laundry Service


PACKAGE A Normal Cleaning (Wash, Dry, Fold)
RM60.00   RM2.50/piece

PACKAGE B Dry Cleaning - Price / Piece


RM110.00 • Baju Kurung or Baju Melayu - RM8.00
• Blazer – RM10.00
• Jacket, Coat - RM9.00
(8 marks)
c) Given the following array declaration in Java application:

PearlService[ ] customers = new PearlService[100];

Assume that the appropriate data have been stored in customers that consists of both
MaidService and LaundryService records.

Write a Java program segment in application that perform the following tasks:

i. Calculate and display the total charges collected for dry cleaning service of blazer
type
(7 marks)

ii. List all the information of all customers including the charges who chose maid
services for every daily maid package.
(6 marks)

You might also like