You are on page 1of 5

Name:Muhammad Hairil bin Shaharudin 2020834824

Group:A4CS2303A
Lab Exercise: Polymorphism

Given the following classes and inheritance hierarchy, which are used to store various types of
tailor services:

TailorService

BajuKurung BajuMelayu
and the following are definitions for the TailorService, BajuKurung, and BajuMelayu classes:

abstract class TailorService


{
protected String custName; protected String
receiptNum; protected double deposit; protected
boolean delivery; public TailorService(…){…}
// sets all data.

public String getName(){…} // returns the name public


String getReceipt(){…} // returns the receipt number.
public double getDeposit(){…} // returns the deposit.
public boolean getDelivery(){…} // returns the
delivery. public abstract double payment();
}//end of class Tailor Service

class BajuKurung extends TailorService


{
private int type; //type of baju kurung
private boolean embroidery //either the customer choose to add
// embroidery to the baju kurung
public BajuKurung (…){…} // sets all data.

public double addEmbroidery() {…}


/* return additional charge for adding embroidery. Customer will be
charge additional RM25.00 if chooses to add the embroidery. */
public double payment() {…}
/* payment is calculated base on the type of clothes made. The total payment
is calculated after adding the extra charges for embroidery.
The rate is as follows:
Type of clothes Price per suite (RM)
================ ==================
Normal Baju Kurung 30.00
Baju Kurung + Lining 60.00 Normal
Baju Kebaya 55.00
Baju Kebaya + Lining 110.00
*/

}//end of class BajuKurung


Name:Muhammad Hairil bin Shaharudin 2020834824
Group:A4CS2303A

class BajuMelayu extends TailorService


{
private int type; public BajuMelayu (…){…}
// sets all data.

public double payment(){…}


/* payment is calculated base on the type of clothes made. The rate is
as follows:
Type of clothes Price per suite (RM)
========================= ====================
Baju Melayu Cekak Musang 75.00
Baju Melayu Teluk Belanga 95.00
*/

}//end of class BajuMelayu

a) Implements all the classes described.


Name:Muhammad Hairil bin Shaharudin 2020834824
Group:A4CS2303A

b) Write a Java application which uses the concept of polymorphism to:

i) Declare an array of objects to store data on various types of tailor services.

ii) Calculate and display the number of customer who chooses to make baju kurung or
baju kebaya with embroidery option.

iii) Calculate and display the total amount of payment of all customers including delivery
service charge that costs RM5.00. Display also total income received by the tailor.
Display the output in the following format:

CUSTOMER’S NAME TOTAL CHARGE (RM)


=============== ==================
…………… …………………
…………… …………………
TOTAL INCOME: RM ………………
Name:Muhammad Hairil bin Shaharudin 2020834824
Group:A4CS2303A
b)

OUTPUT:
Name:Muhammad Hairil bin Shaharudin 2020834824
Group:A4CS2303A

You might also like