CSC186 FinalTestMacJuly2020
CSC186 FinalTestMacJuly2020
CSC186 FinalTestMacJuly2020
FINAL TEST
PART A
QUESTION 1 (5 marks)
Superclass Subclass
Has a more general concept Has a more specific concept
Subclasses can inherit attribute Inherit attribute from superclass and can
extend
(4 marks)
(1 mark)
2
CONFIDENTIAL CS/AUGUST2020/CSC186
Class : DateTime
Data member :day (int) //e.g : 02, 05
month (int) year (int) time //e.g : 07, 11
(String) //e.g : 2019, 2020
//e.g : 08:30am, 2:00pm
DateTime(int day,int month,int year,String time)
toString()
Subclass : OnlineLearning
Data member : platform(String) //eg:telegram, googleMeet
Constructor
A mutator
Accessor Printer
method
a) Refer to the above superclass and subclass, suggest another relevant subclass and list
ONE (1) unique attribute belong to the subclass.
b) Write a complete class definition for subclass in a) with the stated attribute,
constructor, accessor and toString() method.
(8 marks)
3
CONFIDENTIAL CS/AUGUST2020/CSC186
c) Write a complete class application that will display the following sample output.
(Hints: use array of object for OnlineLearning).
Sample output;
else if(online[i].getPlatform().equalsIgnoreCase(“Whatsapp”){
w++;}
else if(online[i].getPlatform().equalsIgnoreCase(“googleMeet”){
g++;}
else if(online[i].getPlatform().equalsIgnoreCase(“Telegram”){
t++;}
else{
o++}
}
4
CONFIDENTIAL CS/AUGUST2020/CSC186
SOP(“………..” + u)
……………………..
(10 marks)
5
CONFIDENTIAL CS/AUGUST2020/CSC186
QUESTION 3 (5 marks)
The following diagram shows class Event is a superclass of subclass Birthday and
Wedding. Class Event has been defined as an abstract class.
Event
Birthday Wedding
because event serves as a blueprint for different types of event. Also because even cannot
create object by itself. Need to have subclasses such as …..
(2 marks)
b) Explain ONE (1) feature of method overriding and suggest ONE (1) method
overriding based on the classes above.
(3 marks)
6
CONFIDENTIAL CS/AUGUST2020/CSC186
ALAM company asked the IT Base Sdn. Bhd to develop a payroll system to handle the salary for
their part time workers weekly. The workers are two types; Hourly workers are paid regardless
of the number of hours worked and receive overtime pay RM8.00 per hour for all hours worked
in excess of 40 hours; Base-salary-plus-commission workers receive base salary plus a
percentage 8% commission of their sales. For the current pay period, the company has decided to
reward hourly workers by adding 12% to their total salary and base-salary-plus-commission
workers by adding 10% to their base salaries.
A group of programmers from IT Base Sdn Bhd have just finished in figure out their idea of this
payroll system by using the UML class diagram. Figure 1 shows the inheritance hierarchy of the
polymorphic worker payroll application weekly.
Worker
Table 1 shows each of the three classes with its data respectively.
7
CONFIDENTIAL CS/AUGUST2020/CSC186
As a programmer of IT Base, you are assigned to write a program that uses polymorphism concept
to perform the following tasks:
b) Define the Hourly worker class with its unique attribute, normal constructor,
calcGrossSalary(), calcOvertime(), calcNewSalary() and printer
method. The method calcGrossSalary() will calculate the gross salary by
multiplying the hours work and hourly wage. Method calcOvertime() will
calculate the overtime payment obtained. Method calcNewSalary() will calculate
a new salary by adding the gross salary obtained plus 12% increment of gross salary and
overtime. The printer method will return all the information of this worker.
(10marks)
c) Write a complete Java application named WorkerApp that will do the following
tasks:
8
CONFIDENTIAL CS/AUGUST2020/CSC186
counthw++;}
countbw++;}
9
CONFIDENTIAL CS/AUGUST2020/CSC186
Display the name together with Social Security Number whose get the highest
salary after incrementing for both types of workers.
(8 marks)
1
0