CSC186 FinalTestMacJuly2020

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

UNIVERSITI TEKNOLOGI MARA

FINAL TEST

COURSE : OBJECT ORIENTED PROGRAMMING


COURSE CODE : CSC186
SEMESTER : MARCH – JULY 2020
TIME : 2 ½ HOURS

1. This question paper consists of one (1) part : PART A (4 Questions)

2. Answer ALL questions. Start each answer on a new page.

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO


This examination paper consists of 7 printed pages
CONFIDENTIAL CS/AUGUST2020/CSC186

PART A
QUESTION 1 (5 marks)

a) Explain TWO (2) differences between superclass and subclass.

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)

b) Show ONE (1) example of a superclass and subclass.

(1 mark)

2
CONFIDENTIAL CS/AUGUST2020/CSC186

QUESTION 2 (20 marks)

Given the following superclass and subclass;

Superclass : Learning Data


member :code //e.g : CSC186, ITS232
datetime //e.g : 05112020 8:30am
Method :Learning (String code, DateTime dt)
A mutator Accessors
public String determineCourse()
//to determine and return course program based on code
toString()

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.

PhysicalLearning; String place


(2 marks)

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;

Course Program Code Date Time Platform


Computer Science CSC186 20/04/2020 8:00am Ufuture
Computer Science CSC248 21/042020 2.00pm Whatsapp
Mathematic MAT163 21/04/2020 4:00pm googleMeet
Computer Science CSC253 21/04/2020 10:00am Telegram
Statistic STA116 22/04/2020 8:00am Ufuture
….
….
….(many more records)
….
Total class using Ufuture = 2 Total
class using GoogleMeet = 1 Total
class using Telegram = 1
Total class using other platforms = 1

SOP(“enter num of online learning”)


Int numOnlineLearning = scanner.nextLineInt();

OnlineLearning [] online = new OnlineLearning[numOnlineLearning];

for(int i=0; i<online.length; i++){


SOP(online[i].determineCourse() + online[i].getCode() + online[i].getDateTime().toString() +
online[i].getPlatform); }

for(int i=0; i<online.length; i++){


if(online[i].getPlatform().equalsIgnoreCase(“Ufuture”){
u++;}

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

a) State why class Event is defined as an abstract class?

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.

Method overriding is where a subclass provides a specific implementation to


define a method in superclass. This allows the subclass to extend the method
without changing the method name in superclass. For example method calcPrice().

(3 marks)

6
CONFIDENTIAL CS/AUGUST2020/CSC186

QUESTION 4 (20 marks)

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

Hourly worker BasePlusCommission Worker

Figure 1: UML Diagram or worker payroll application

Table 1 shows each of the three classes with its data respectively.

Table 1: Classes and Data


Class Name Data
Worker Name, Social Security Number (SSN)
Hourly worker Name, SSN, hourly rate = RM25.00,
hours worked
BasePlusCommission Worker Name, SSN, gross sales, commission
rate=8% , base salary

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:

a) Class Worker is an abstract class contains attributes, normal constructor, accessors,


toString() method, abstract methods named calcGrossSalary() and
calcNewSalary(). Write abstract method for calcGrossSalary() and
calcNewSalary() only.
(2 marks)

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.

Public double calcGrossSalary(){


Gross = hoursWorked * 25;
Return gross;}

Public double calcOvertime(){


If(hoursWorked>40)
ot = (hoursWorked – 40) * 8
return ot;}

Public double calcNewSalary(){


new = 0.88 * (calcGrossSalary() + calcOvertime());
Return new;}

(10marks)

c) Write a complete Java application named WorkerApp that will do the following
tasks:

8
CONFIDENTIAL CS/AUGUST2020/CSC186

 To store data on two types of worker(ada 2 array). The number of data to be


stored for each worker is given by the ALAM Company.

SOP(“enter number of hourly worker: “);


Int h = scanner.nextInt();
HourlyWorker [] hw = new HourlyWorker[h];

SOP(“enter number of base plus commision worker: “);


Int b = scanner.nextInt();
baseWorker [] bw = new BaseWorker[b];

for(int i=0; i<hw.length; i++)


SOP(“………..”);
…………………..
Hw[i] = new hourlyWorker(……………);

for(int i=0; i<bw.length; i++)


SOP(“………..”);
…………………..
bw[i] = new baseWorker(……………);

 Calculate and display the number of Hourly workers and


BasePlusCommission workers.

for(int i=0; i<hw.length; i++){

counthw++;}

for(int i=0; i<bw.length; i++){

countbw++;}

SOP(“number of Hourly workers: “ + counthw);


SOP(“number of BasePlusCommission workers: “ + 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.

if(hw[i].calcNewSalary() > bw[i].calcNewSalary()) {


SOP(“highest salary: “);
SOP(“Name: “ + hw[i].getName() + “Social Security Number: “ + hw[i].getSSN()); }

Else if(hw[i].calcNewSalary() < bw[i].calcNewSalary()){


SOP(“highest salary: “);
SOP(“Name: “ + bw[i].getName() + “Social Security Number: “ + bw[i].getSSN());}

(8 marks)

1
0

You might also like