0% found this document useful (0 votes)
3 views3 pages

Pre-Lab_REVISION JAVA AND OOP

The document outlines a revision on object-oriented programming, focusing on class and object basics, inheritance, polymorphism, and object arrays. It includes tasks such as creating constructors, accessor/mutator methods, and surface area calculations for a Square and Cube class, as well as managing customer types for a beauty spa. Additionally, it emphasizes the implementation of polymorphism in handling different customer types and calculating service prices based on membership and discounts.

Uploaded by

suouasashi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Pre-Lab_REVISION JAVA AND OOP

The document outlines a revision on object-oriented programming, focusing on class and object basics, inheritance, polymorphism, and object arrays. It includes tasks such as creating constructors, accessor/mutator methods, and surface area calculations for a Square and Cube class, as well as managing customer types for a beauty spa. Additionally, it emphasizes the implementation of polymorphism in handling different customer types and calculating service prices based on membership and discounts.

Uploaded by

suouasashi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

REVISION OBJECT-ORIENTED PROGRAMMING

Question 1 – Basic Class and Object

Question 2 – Inheritance Concept


Given the following Cube subclass is inherited from Square superclass.

Superclass : Square
Attributes :
double height; //height of a square
double width; //width of a square
double surfaceArea;//the surfaceArea calculate for a square
Methods :-
double computeSurfaceArea();
// calculate the surface area of a square
// (height * width) and return the value
Subclass : Cube
Attributes :
double depth; //depth of a cube
Methods :-
double computeSurfaceArea();
// calculate the surface area of a cube
// (surfacearea of square * depth) and return the value.

a) Write the normal constructor for superclass and its subclass.


b) Write the mutator and accessor methods for superclass and its subclass.
c) Write the processor methods computeSurfaceArea() for superclass and its subclass and
return the calculated surface area value.
d) Write an application named CalculateSurfaceArea. Declare a Square object and a
Cube object, input all data and displays the surface area of the objects.

Question 3 – Polymorphism and Object Array

Given the following classes and inheritance hierarchy which are used to store various types of
CUSTOMERS for Indah Raya Beauty Spa:

CUSTOMER

VIP REGULAR

The class CUSTOMER has three fields: name, customerCat (VIP/REGULAR) and member with
boolean type. Jjjjjjjj888888VIP class is inherited from class CUSTOMER. Its new attribute is
price and vipService (Scrubs & wraps (S)/ Body Massages(B)). Meanwhile, REGULAR class also
inherited from class Customer and has three fields: price & regularService(Body Massages(B)/
Facial(F))and newPrice. Two of subclasses have a function display () to display all info.
a) Define the constructor and getters for superclass CUSTOMER and its subclasses VIP and
REGULAR.

b) VIP subclass has a method named calcNewPrice() which returns new price after discount for
the service at this spa.REGULAR class has a method calcService() to calculate the price should
customer pay after discount.

Customer Type Of Service PRICES(RM) DISCOUNT Member


Category
VIP Scrubs & wraps (S) 300 15% RM50
Body Massages(B) 250
REGULAR Body Massages(B) 200 10% RM10
Facial(F) 150

c) Write the method calcNewPrice() for the VIP and calcService() for REGULAR based on table
above.If the customer is the member at spa, member’s price will be deducted from the price
after discount.
d) Apply Polymorphism concept. Write an application program for the following Task: -
• To declare an array of object for Customer which have 10 elements
• Input all the info needed. Mix all customer type (VIP/REGULAR)
• Count number of VIP customers come to Spa.
• Calculate company total income from both customer types.
• Count the number of REGULAR customers who are booking body massage and display
the information customer in detail.

You might also like