CSC186 – Object Oriented Programming
Academic Session March2024 – July 2024
Lab Assignment 5- Inheritance
Course Outcomes (CO) LO1 LO2 LO3
CO1
CO2 √ √ √
CO3
1.1 Given the following superclass named Food and subclass named WesternFood.
Super Class : Food
Attributes : String name; // customer’s name
int quantityOfOrder; //quantity order made
boolean member; //true – if member, otherwise
//false
Methods : Constructor, mutator, retriever, printer
Sub Class : WesternFood
Attributes : int foodSet; //1- lamb chop, 2- chicken
//chop, 3 – fish and chip
boolean desert; //true – if wants banana
//pie, otherwise false
Methods : Constructor, mutator, retriever, processor, printer
a) Complete the above classes by considering the following methods:
i. Write the normal constructor methods.
ii. Write the mutator methods for each attribute.
iii. The accessor methods for each attribute
iv. Write the printer method.
v. Write the processor methods named Payment() which calculates and returns the
amount to be paid by the customer based on the following table:
Set Set Description Amount (RM)
1 Lamb Chop 30.00
2 Chicken Chop 20.00
3 Fish and Chip 15.00
(MNOS2024) 1|Page
The customers need to pay extra RM 10.90 if they want the set that comes with dessert.
Besides, 10% discount will be given to the members.
b) Write a Java application which uses the concept of inheritance to:
i. Store data into an array of objects. The number of data to be stored and information
on each of the customers is given by the user.
ii. Display the details of customer's information, including the payment.
iii. Count and display the number of customers who make a desert order.
iv. Calculate and display the total amount from the member's customers.
v. Calculate and display the total amount of charges for all customers.
vi. Display the details of customer’s information who make an order the Lamb Chop set.
1.2 Given the following inheritance hierarchy:
Employee
-name:String
-id: int
-Position:String
+Employee()
+Employee(String,int,String)
+setName(String):void
+setId(int):void
+setPosition(String):void
+getName():String
+getId():int
+getPosition():String
+toString():String
Permanent PartTime
-basicSalary:double -ratePerHour:double
-houseAllowance:double -totWorkingHour:double
+PartTime()
+Permanent() +PartTime(String,int,String,double, double)
+Permanent(String,int,String,double, double) +setRatePerHour(double):void
+setBasicAllowance(double):void +setTotWorkingHour(double):void
+setHouseAllowance(double):void +getRatePerHour():double
+getBasicAllowance():double +getTotWorkingHour():double
+getHouseAllowance():double +calcSalary():double
+calcSalary():double +toString():String
+toString():String
Write a Java application to do the following tasks:
• Ask the user to enter number of employees in the company.
(MNOS2024) 2|Page
• Input the appropriate data for each employee. Use array of objects to store the details of
the employees.
• Print a slip for each employee that shows the details of the employee including the payment.
• For processor (method calcSalary()):
❖ Permanent worker : The salary is given based on the following formula:
Salary = basic salary + house allowance – epf – income tax
Note: epf – 11% from the basic salary,
income tax – 7% from the basic salary
❖ Part time: The salary is given based on the following formula:
Salary = rate per hour * total working hour
• At the end of the process, print a report that shows the following information:
No. of permanent employees: ??
No. of part-time employees: ??
Total payment for permanent employees (RM): ??
Total payment for part-time employees (RM): ??
Total payment for all employees (RM): ??
1.3 By referring to the Final Examination Paper (December 2019), PART B, QUESTION 3. Write a
complete Java program.
1.4 By referring to the Final Examination Paper (February 2023), PART B, QUESTION 3. Write a
complete Java program.
1.5 By referring to the Final Examination Paper (July 2023), PART B, QUESTION 3. Write a complete
Java program.
1.6 By referring to the Final Examination Paper (January 2024), PART B, QUESTION 3. Write a
complete Java program.
(MNOS2024) 3|Page