CONFIDENTIAL 2 CS/DEC 2022/CSC186
PART A
QUESTION 1 (10 marks)
An insurance company wants you to develop an automated process for calculating vehicle
insurance. The company requires information about vehicle such as market value (RM), total
passenger and cubic capacity (CC) of the vehicle. The range of cubic capacity is shown in the
table below:
Cubic Capacity (CC)
0 - 1400
1401 – 1650
1651 – 2200
2201 – 3050
3051 - 4100
Based on the above information and using object-oriented approach, answer the following
questions.
a) Explain the concept of encapsulation.
(1 mark)
b) Identify ONE (1) class name and THREE (3) attributes in the class.
(2.5 marks)
c) Determine ONE (1) object by assigning three suitable values.
(1.5 marks)
d) The system can calculate the vehicle insurance for three different types of vehicles such
as motorcycle, car and lorry.
i) Draw a diagram to show the relationship for all types of vehicles.
(2 marks)
ii) Identify the relationship name. Describe the concept of the relationship.
(3 marks)
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 3 CS/DEC 2022/CSC186
QUESTION 2 (20 marks)
Happy Food is selling baby foods such as puree, food powder and fruit cereal. The company
is planning to develop the inventory system to assist them in keeping the inventory using the
following information.
Product name: Spinach Puree
Age started (months): 6
Stock Price: RM4.50
Quantity left: 130
Product name: Banana Cereal
Age started (months): 10
Stock Price: RM11.75
Quantity left: 48
Product name: Chicken Powder
Age started (months): 8
Stock Price: RM15.10
Quantity left: 80
.
.
.
a) Write a complete class definition for class Product that contains all attributes as
mentioned above and the following methods.
x Normal constructor.
x Accessor methods for each data member.
x toString() method that returns all data members of the class.
x calculateSellingPrice() method that finds and returns the selling price for
customer. Product type contains in product name. For example, product type of
Spinach Puree is puree, Banana Cereal is cereal and Chicken Powder is powder.
The calculation of selling price is based on the following table:
Product Type Selling Price Percentage
Puree 150%
Powder 145%
Cereal 135%
selling price = stock price x selling price percentage
(10 marks)
b) Write a Java main program to perform the following tasks:
i) Declare an object of type Product named prod, read and store all data into the
object.
(3 marks)
ii) Display all information of the product with the quantity left is less than 50.
(2 marks)
iii) Find and display the gross profit for the product based on the formula below.
Gross Profit = (Selling Price x Quantity) - (Stock Price x Quantity)
(3 marks)
iv) Display the product name for baby above than 7 months old.
(2 marks)
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 4 CS/DEC 2022/CSC186
QUESTION 3 (5 marks)
Given the following class diagram for Performer and Dancer.
Based on the diagram above, answer the following questions:
a) Describe the relationship between two classes.
(1 mark)
b) Siti Norliza is an artist singing a balada song together with two dancers. Balada is a type
of genre. The details of dancers are as follows.
Dancer Name Gender
1 Syafiq Ibrahim M
2 Nadhirah Nuqman F
Referring to the information in b), write Java program statements for the tasks below.
i) Declare and create an array named arrayD to store all dancers as mentioned above.
(1 mark)
ii) Create two dancers and store the objects into the array in b i).
(2 marks)
iii) Declare and create one Performer object.
(1 mark)
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 5 CS/DEC 2022/CSC186
QUESTION 4 (15 MARKS)
Smile Always Gift Shop is a gift shop that offers a variety of gifts such as fresh flowers,
chocolates, candies and many more for their customers. In order to make their business more
organized, especially in keeping track of customer records including the distance to deliver
the gift, the owner is planning to move from a manual to a computerized system. Thus, you
are assigned to develop an application using object-oriented approach.
The following table depicts the hot selling products for this shop.
Customer who become a member receives a 10% discount on purchases of at least RM200.
The following is a class definition for GiftProduct.
public class GiftProduct
{
private Customer cust; //Contains data of a customer
//such as name (String),
//idMember (String),
//address (String),
//membership (boolean)
private String catCode; //the category code.
private char productCode; //the product code.
private int quantity; // the quantity the customer would
//like to purchase.
private int distance; //the distance in kilometer.
//default constructor
//getter methods
//setter method that receives parameters for all data
//members for GiftProduct and Customer
//processor methods
//printer method to returns all information
Based on the class GiftProduct above, answer the following questions.
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 6 CS/DEC 2022/CSC186
a) Describe the relationship between class GiftProduct and Customer.
(1 mark)
b) Define the following methods for class GiftProduct.
i) Write a method named calcTotalAmount() to find the total amount that the
customer need to pay. The total amount must include the product price, discount (if
any) and delivery costs as listed below:
(6.5 marks)
ii) Write a method named cMemberYear()to return year of membership. The year of
membership can be accessed by id member. The illustration shows how the year
can be accessed. For example, id member is 2022-00001.
2022-00001
year unique
number (2 marks)
c) In the main(), write Java statements to perform the following tasks.
i) Create an array named buyer to store 100 GiftProduct objects. (1 mark)
ii) Assume all data has been stored into the array. Change data on third object of
buyer with the following information.
GiftProduct Details
Category Code : BS123
Product Code :B
Quantity :2
Distance : 60
Customer Details
Name : Sophia Al-Karim
ID Member : 2022-00034
Address : PT01, Bukit Ilmu, Machang, Kelantan
Membership : true (2 marks)
iii) Display number of customers who become member in 2022. (2.5 marks)
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL