0% found this document useful (0 votes)
41 views9 pages

CSC186 FinalFeb2021

The document discusses a course registration system with classes like courseRegistration, onlineClass, and methods like calculateFee. It provides sample code and asks to write code to perform tasks like creating objects, setting attributes, overriding methods, and calculating fees.

Uploaded by

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

CSC186 FinalFeb2021

The document discusses a course registration system with classes like courseRegistration, onlineClass, and methods like calculateFee. It provides sample code and asks to write code to perform tasks like creating objects, setting attributes, overriding methods, and calculating fees.

Uploaded by

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

CONFIDENTIAL 1 CS/FEB 2021/CSC186

UNIVERSITI TEKNOLOGI MARA


FINAL ASSESSMENT

COURSE : OBJECT ORIENTED PROGRAMMING


COURSE CODE : CSC186
EXAMINATION : FEBRUARY 2021
TIME : 3 HOURS

1. This question paper consists of 3 Questions.

2. Answer ALL questions by using A4 papers. Start each answer on a new page. Scan

and Save as PDF in one file only.

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


This examination paper consists of 6 printed pages

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 2 CS/FEB 2021/CSC186

QUESTION 1

Kolej Universiti Cerdik Bijaksana offers two elective courses that can be enrolled by many students
from many programs. The following text file, enrollment.txt contains the enrollment records
of students for courses CTU553 and CTU551:

Assume the text file consists of thousands of student records. The attributes for each record are
student ID, student name, program and course. The following information is about class Enroll:

Class:
Enroll

Attributes:

String studID;
String
studName;
String program;
String course;

Methods:

//default constructor
//normal constructor
//setter
//getters
boolean isCTU551() //returns true if the student register CTU551
toString()

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 3 CS/FEB 2021/CSC186

Write a complete JAVA program to perform the following tasks:


a) Read the records from file enrollment.txt, one by one and store it in an Enroll
object named enroll1.
b) Count and display the number of students who register CTU551.
c) Store the student ID and student name of CS240 students who register CTU553 into an output
file named CS240_CTU553.txt.
d) Write any one exception handling operations to deal with the file input-output errors.

(15 marks)

QUESTION 2

Harold Cohen is one of the most progressive private higher education institutions. Due to a high
demand in computer science and engineering studies, the institution offers online classes to
prospective students. The following diagram shows the inheritance hierarchy used in developing a
course registration system for the institution.

public class courseRegistration{

private String studentID;


private String
studentName; private int
studentAge; private char
studentGender;
private int studentType; //1.undergraduate or 2.postgraduate

//normal constructor
//accessor methods
//mutator method
//printer method
//public double calculateFee(){…}

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 4 CS/FEB 2021/CSC186

a) Based on the above diagram, perform the following tasks.


i. Identify the superclass and subclass.

(2 marks)

ii. Identify an additional data member for the subclass.


Boolean hasLiveSession
(1 mark)
Public static void main(String[] args)

iii. Which method implements method overriding. Give a reason for your answer.

Method calculateFee() because it has same method name in different classes

(2 marks)

b) Write a complete class definition for onlineClass that includes the following methods:

i. A normal constructor.
ii. A mutator method to initialize its additional data member.
Public void setHasLiveSession(Boolean hasLiveSession){
This.hasLiveSession = hasLiveSession;}
iii. An accessor method. = getProgramCode()
iv. An overriding printer method named toString() that displays information of online
class.
v. Processor method named calculateFee()that returns the price after discount. The
fee is calculated based on the following table:

Program Code Discount rate (%)

Undergraduate Postgraduate

COMP 40 30

ENG 35 25

*Basic fee for undergraduate and postgraduate are RM1600 and RM2100 respectively.

Public double calculateFee(){


If(programCode.equalsIgnoreCase(“COMP”)
If(studentType == 1)
Price = 0.6 * 1600;
Else if(studentType == 2)
Price = 0.7 * 2100;
Else if(programCode.equalsIgnoreCase(“ENG”)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 5 CS/FEB 2021/CSC186

If(studentType == 1)
Price = 0.65 * 1600;
Else if(studentType == 2)
Price = 0.75 * 2100;
Return price;}

(10 marks)

c) Write the main program to perform the following tasks:

i. Create an array of ONE HUNDRED (100) onlineClass objects named online.

onlineClass [] online = new onlineClass [100];

ii. Input and store all information about students into the array.

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


SOP(“……………”;
………………………

Online[i] = new onlineClass(………………)

iii. Update program code from ENG to COMP for student ID “2017111222”.

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

If(online[i].getStudentID().equalsIgnoreCase(“2017111222”){

Online[i].setProgramCode(“COMP”); }
}

iv. Calculate and display the total fee collected from engineering program for
undergraduate students.

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


If(programCode.equalsIgnoreCase(“ENG”) && studentType == 1){

Total = total + online[i].calculateFee(); }


}

SOP(“total fee: “ + total);

v. Display the program code enrolled by a student named “Alexander”.

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

If(online[i].getStudentName().equalsIgnoreCase(“Alexander”){
SOP(online[i].getProgramCode; }
}

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 6 CS/FEB 2021/CSC186

(10 marks)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 7 CS/FEB 2021/CSC186

QUESTION 3

One IT Solution Sdn Bhd is a software house company. They are planning to provide a system to
store data about teachers. Given are SchoolTeacher and KindergartenTeacher subclasses
which are inherited from Teacher superclass.

Superclass: Teacher Attributes:


String name; String icNo;
String subjectTaught; int yos;
// identification card no
// English, Math, History
// year of service

Methods:
normal constructor accessor methods toString()
abstract double calcSalary()

Subclass: SchoolTeacher Attributes:


String grade;//teacher grade, e.g: DG41, DG44, DG48

Methods:
normal constructor accessor method toString()
double calcSalary()

Subclass: KindergartenTeacher Attributes:


int otHours;//overtime hours per month

Methods:
normal constructor accessor method toString()
double calcSalary()

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 8 CS/FEB 2021/CSC186

a) Write the normal constructor for subclass SchoolTeacher.


(2 marks)

b) Write the definition of method calcSalary() for both subclasses that calculate and return the
teacher’s salary based on the following information.

i. The salary of school teacher is calculated based on the grade as shown in Table 1:

Table 1 : School Teacher Salary


Grade Salary (RM)
DG41 2000
DG44 3400
DG48 5000
DG52 5600

ii. For kindergarten teachers, the salary is calculated based on the year of service as shown in
Table 2 and overtime hours.

Table 2 : Kindergarten Teacher Salary


Year of Service Basic salary (RM)
<= 2 1300
<= 5 1900
>5 2100

Each overtime hour will be paid RM15. Salary for the kindergarten teachers is the total of basic
salary and overtime hours pay.

If(yos<=2)
Salary = 1300;
Else if(yos<=5)
Salary = 1900;
Else if(yos>5)
Salary = 2100;

salary = otHour * 15;

return salary;

(6.5 marks)

c) Based on the classes given, write Java statements to do the following:

i. Declare an array of 20 Teacher objects named teach.

Teacher [] teach = new Teacher[20];

(1 mark)
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 9 CS/FEB 2021/CSC186

ii. Display the information of English teachers who have been teaching for more than 10
years.

For(int i=0; i<teach.length; i++)


If(teach[i].subjectTaught.equalsIgnoreCase(“English”) && teach[i].getYos > 10){

SOP(teach[i].toString()); }
}

(3 marks)

iii. Display the name and salary of school teachers whose grade is DG44.
For(int i=0; i<teach.length; i++)
If(teach[i] instanceOf SchoolTeacher){
SchoolTeacher st = (SchoolTeacher) teach[i];
If(st.getGrade().equalsIgnoreCase(“DG44”)) {
SOP(st.getName());
SOP(st.calcSalary()); }
}
}

(3.5 marks)

iv. Calculate and display the total overtime hours done by the teachers.
For(int i=0; i<teach.length; i++){
If(teach[i] instanceOf KindergartenTeacher) {
KindergartenTeacher kt = (KindergartenTeacher) teach[i];}

Total = total + kt.getOtHours()}

SOP(“total overtime hours: ” + total);

(4 marks)

END OF QUESTION PAPER

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

You might also like