CSC186 FinalFeb2021
CSC186 FinalFeb2021
2. Answer ALL questions by using A4 papers. Start each answer on a new page. Scan
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()
(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.
//normal constructor
//accessor methods
//mutator method
//printer method
//public double calculateFee(){…}
(2 marks)
iii. Which method implements method overriding. Give a reason for your answer.
(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:
Undergraduate Postgraduate
COMP 40 30
ENG 35 25
*Basic fee for undergraduate and postgraduate are RM1600 and RM2100 respectively.
If(studentType == 1)
Price = 0.65 * 1600;
Else if(studentType == 2)
Price = 0.75 * 2100;
Return price;}
(10 marks)
ii. Input and store all information about students into the array.
iii. Update program code from ENG to COMP for student ID “2017111222”.
If(online[i].getStudentID().equalsIgnoreCase(“2017111222”){
Online[i].setProgramCode(“COMP”); }
}
iv. Calculate and display the total fee collected from engineering program for
undergraduate students.
If(online[i].getStudentName().equalsIgnoreCase(“Alexander”){
SOP(online[i].getProgramCode; }
}
(10 marks)
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.
Methods:
normal constructor accessor methods toString()
abstract double calcSalary()
Methods:
normal constructor accessor method toString()
double calcSalary()
Methods:
normal constructor accessor method toString()
double calcSalary()
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:
ii. For kindergarten teachers, the salary is calculated based on the year of service as shown in
Table 2 and overtime hours.
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;
return salary;
(6.5 marks)
(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.
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];}
(4 marks)