CSC186-AnswerSchemeTest MacAugust2022
CSC186-AnswerSchemeTest MacAugust2022
ANSWER SCHEME
PART A
Consider the following payslip of an employee who employed at the stated company. The
payslip is for the month of May 2022.
Employee Payslip
May 2022
INCOME
Total Working Hours (RM) : RM 1,000.00
Total Overtime Hours (RM) : RM 252.50
Total Salary (RM) : RM 1,252.50
Given the class name is Payslip. Based on the above information, answer the following
questions.
Abstraction applied to the above payslip. There is a process of hiding the implementation
details from the user, only the functionality will be provided to the user. In other words, the
user will have the information (total working hours(RM) and total overtime hours (RM)) on
what the object does instead of how it does it (the calculation details is hidden).
Answer:
EmployeeName String
EmployeePost String
EmployeeWorkingHour double / float
EmployeeOverTime double / float
(3 marks)
Answer:
d) Write a Java statement to declare and create the object as stated in the payslip.
(2 marks)
Answer:
Payslip e1 = new Payslip(“Sudin bin Ajis”, “Sales Assistant”, 20.0, 50.5);
Umrah.com organizes several umrah packages. Customer may book online from their
website by providing details such as name, address, umrah category, and number of
participants. The class Umrah has the following methods:
• a normal constructor.
• a mutator named setUmrah() for all data members.
• a mutator for umrah category.
• accessor methods for each data member.
• a processor method named calculateCharge() to calculate and return the
charge that should be paid by the customer. The calculation is based on the
following table:
if(umrahCategory.equalsIgnoreCase("Saudi Airlines"))
price = 8190 * participants;
else if(umrahCategory.equalsIgnoreCase("Malaysia
Airlines"))
price = 9490 * participants;
3m
else
return price;
}
}
Answer:
//i) 0.5m
Umrah umrahSyawal; //0.5m
//ii) 3m
System.out.println("Enter Name:");
name = input.nextLine();
System.out.println("Enter Address:");
address = input.nextLine();
System.out.println("Enter Umrah Category:");
umrahCat = input.nextLine();
System.out.println("Enter number of participants:");
part = input.nextInt();
//iii) 1.5m
Umrah umrahRamadhan = new Umrah(“Sharif bin Shahrul”,”Taman
Merdeka”,”Saudi Air”, 7);
//iv) 3.5m
if
(umrahSyawal.calculateCharge()>umrahRamadhan.calculateCharge())
System.out.println(“Umrah Syawal :“+
umrahSyawal.getName()+umrahSyawal.getAddress());
else if
(umrahRamadhan.calculateCharge()>umrahSyawal.calculateCharge())
System.out.println(“Umrah Ramadhan
:”+umrahRamadhan.getName()+umrahRamadhan.getAddress());
else
System.out.println(“they have equal charge”);
//v) 1.5m
if (umrahSyawal.getName().equalsIgnoreCase(“Kamal”)
umrahSyawal.setCategory(“Malaysia Airlines”);
Long Songket is a boutique specializing in selling Songket fabrics. It sells four types of
Songket, namely Songket Kesuma, Songket Bunga Tabur, Songket Kaktus, and Songket
Tenun Kasih. In order to make their business more organized, especially in keeping track of
customer records, the boutique is planning to move from a manual to a computerized system.
The system will be able to keep track of the customer records, calculate the number of songket
sold according to type, calculate sales according to customer type and calculate the total sales
of the boutique. The boutique has three types of customers, which are walk-in customers,
agents and stockists. Walk-in customers will receive a 15% discount for total purchases above
RM1000 and no discount for total purchase less than RM1000. As of agent, every purchase
will be entitled for 20% discount and stockists will receive a 35% discount. Figure 1 below
shows the class diagram of the proposed system:
Answer:
else if(type.equalsIgnoreCase("Kaktus"))
//0.5
return 240 * quantity;
else
return 320 * quantity; //0.5
}
Answer:
ii) Two mutator methods by referring to the following statements in Java main program.
cust1.setDetails(“Agent”, “0112345678”);
cust2.setDetails(“Kaktus”, 3);
(3 marks)
Answer:
public void setDetails(String type, String contact)
{ custType = type; //1m
contactNo = contact;
}
Overloading is having more than one method with the same name but different list of
parameters. ---- //1m
(3.25 marks)
else if(custType.equalsIgnoreCase(“Agent”))
price = sk.calculatePrice() * 0.80; //0.5
else if(custType.equalsIgnoreCase(“Stockist”))
price = sk.calculatePrice() * 0.65; //0.5
return price; ----//0.5m
}
c) In the Java main program, write program segments to do the following tasks:
(1 mark)
Answer:
(2.75 marks)
Answer:
iii) Update the third object in the array. Assign two new values only to the object as
follow:
Answer:
cust[2].setDetails(“Tenun Kasih”, 5);
iv) The boutique expects the net sales of at least RM15,000 for 20 customers.
Determine either they meet the expectation or not by displaying appropriate
message.
(2.25 marks)
Answer: