0% found this document useful (0 votes)
90 views

CSC435_OCT2022_Test1_Q

This document is a test paper for the Object-Oriented Programming course (CSC435) at Universiti Teknologi Mara for the October 2022 semester. It consists of two parts: Part A with 10 multiple-choice questions and Part B with 2 programming questions, totaling 50 marks. Candidates are instructed to answer all questions in English and use the provided objective sheet for Part A.

Uploaded by

Noor Athirah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

CSC435_OCT2022_Test1_Q

This document is a test paper for the Object-Oriented Programming course (CSC435) at Universiti Teknologi Mara for the October 2022 semester. It consists of two parts: Part A with 10 multiple-choice questions and Part B with 2 programming questions, totaling 50 marks. Candidates are instructed to answer all questions in English and use the provided objective sheet for Part A.

Uploaded by

Noor Athirah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

CONFIDENTIAL CS/OCT 2022/CSC435/TEST 1

UNIVERSITI TEKNOLOGI MARA


TEST 1

COURSE : OBJECT-ORIENTED PROGRAMMING


COURSE CODE : CSC435
EXAMINATION : TEST 1 – SEMESTER OCT 2022
TIME : 1 HOUR 45 MINUTES

INSTRUCTIONS TO CANDIDATES

1. This paper consists of TWO (2) parts: PART A (5 questions)


PART B (3 questions)

2. Answer ALL questions from PART A, and PART B in this question paper.

3. Answer ALL questions in English.

Name/UiTM No.:

Group/Lecturer.:

QUESTION FULL MARKS MARKS

Part A 20

Part B 30

TOTAL MARKS 50

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


This examination paper consists of 12 printed pages
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 2 CS/OCT 2022/CSC435/TEST 1

PART A (20 MARKS)

Answer ALL questions.


Questions must be answered on the objective sheet (provided in this question paper) by
darkening the appropriate square bracket against the question number on the respective
left-hand columns. Each question has only one correct answer.

1. Which of the following statements is TRUE about objects?

A. One class can create many objects.


B. One object is used to create one class.
C. An object belongs to more than one class.
D. Objects are defined using the object keyword in the field declaration.

2. Which of the following statements about object-oriented programming (OOP) are


TRUE?

I. The implementation of a class should be hidden from its client.


II. OOP encapsulates data and functions into a package called objects.
III. Abstraction indicates the essential attributes and behaviors of an object.
IV. The concept of OOP is similar to the concept of top-down design.

A. I, II
B. I, IV
C. I, II, III
D. I, III, IV

3. Which of the following statements does NOT apply to object-oriented programming?

A. Two important concepts in object-oriented programming are classes and objects.


B. Abstraction is the process of representing a computer object into a real-world
object.
C. Inheritance is a powerful feature in Java in which reusing codes are allowed.
D. Through encapsulations, data and functions are intimately tied together.

4. Which of the following features of object-oriented programming promotes code


reusability?

A. Data hiding
B. Encapsulation
C. Inheritance
D. Polymorphism

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 3 CS/OCT 2022/CSC435/TEST 1

5. Which of the following options leads to the portability and security of Java language?

A. Bytecode is executed by JVM.


B. Use of exception handling.
C. Dynamic binding between objects.
D. Provides different access modifiers for variables and methods.

6. Given the following code fraction, what is the output after execution?

public static void main(String[] args) {


String word = “hello”;
String word2 = “ “;
char ch;

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


{
ch = word.charAt(i);
word2 = ch + word2;
}

System.out.println(word2);
}

A. “hello”
B. “olleh”
C. “heoll”
D. “ollhe”

7. Java supports three types of variables: class or static variables, non-static or instance
variables and local variables. Which of the following is TRUE about class or static
variables?

A. Static variables must be accessed with the help of a class object.


B. This type of variable can be accessed without an object.
C. Static variables can make a program’s memory not efficient.
D. The constant keyword is used to declare a static variable.

8. Which of the following methods changes the data of an employee object? Assume an
employee has an id number and a name.

A. public String getName(){ return name;}


B. public void setName(){ String name = this.name;}
C. public String toString(){ return id + name;}
D. public void addName(){ name = “Mr ” + name;}

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 4 CS/OCT 2022/CSC435/TEST 1

9. It is a logical template to create objects that share common attributes and methods.
The definition most likely refers to ___________.

A. an interface
B. an inheritance
C. a class
D. an array

10. Given a program segment below. What is the output after the statements execute?

public class Customer


{
private String id;
private String name;

}

public class CustomerTest


{
public static void main(String[] args)
{
Customer cust1, cust2, cust3;
cust1 = new Customer();
cust2 = new Customer();
cust2 = cust3;

if (cust2 == cust1)
System.out.print(“YES ”);
else
System.out.print(“NO ”);
System.out.println(“THANK YOU ”);
…..
}
}

A. YES THANK YOU


B. NO
C. THANK YOU
D. NO THANK YOU

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 5 CS/OCT 2022/CSC435/TEST 1

Answer form (CSC435 TEST 1):

1 [A] [B] [C] [D] 6 [A] [B] [C] [D]

2 [A] [B] [C] [D] 7 [A] [B] [C] [D]

3 [A] [B] [C] [D] 8 [A] [B] [C] [D]

4 [A] [B] [C] [D] 9 [A] [B] [C] [D]

5 [A] [B] [C] [D] 10 [A] [B] [C] [D]

2m for correct answer


Max = 10m

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 6 CS/OCT 2022/CSC435/TEST 1

PART B (30 MARKS)

Answer ALL questions.

QUESTION 1 (10 MARKS)

a) This year (2022), Suruhanjaya Pilihan Raya Malaysia (SPR) is identifying which
channel (saluran) voters should be. Write a structured Java program (without using
object-oriented approach) to:

I. declare a string variable for name,


II. declare an integer variable for the year of birth,
III. prompt the user to input values for both variables in I and II,
IV. calculate the age, and
V. check and prompt the user with a response message, as shown in the table
below.

Condition/case Response message

Age < 18 [Name] is not allowed to vote.

Age >= 18 and < 36 [Name] is in channel 4.

Age >= 36 and < 45 [Name] is in channel 3.

Age >= 45 and < 60 [Name] is in channel 2.

Age >= 60 [Name] is in channel 1.

*[Name] is the input value from the user.


(7 marks)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 7 CS/OCT 2022/CSC435/TEST 1

b) Assume that you are currently developing a self-checkout system for a grocery shop.
The system will be able to scan products and calculate the total price to pay. Customers
can pay via card or e-wallet.

Identify ONE (1) possible class and TWO (2) proper attributes for the class that can be
developed for the system.
(3 marks)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 8 CS/OCT 2022/CSC435/TEST 1

QUESTION 2 (20 marks)

Given a fragment of Patient class definition:

public class Patient

private String name; //patient’s name

private int wardType; //ward type (1,2,4)

private int day; //number of days stay

private double treatmentFee; //treatment charges

……

a) Complete the class by declaring the following:


i) Normal Constructor.
(2 marks)

ii) Setter and getter for wardType, day and treatmentFee.


(3 marks)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 9 CS/OCT 2022/CSC435/TEST 1

iii) A toString() method.


(2 marks)

iv) Write a processor method calcCharges() to calculate the charges


to be paid by the patients of the hospital. The daily ward charges for each
ward type are shown in the following table:

Ward Type Charges (RM)/day

1 (1-bed) 300

2 (2-bed) 250

4 (4-bed) 100

The charge is calculated based on the given formula:

charges = ward charges + treatment fee

(4 marks)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 10 CS/OCT 2022/CSC435/TEST 1

b) A main class is then written to test the class above. Complete this main class by:
(Assume all getters and setters have been defined for all attributes)

i) Declare an array of Patient named patient with size of 100.


(2 marks)

ii) Calculate and display the average charges for all patients

(4 marks)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 11 CS/OCT 2022/CSC435/TEST 1

iii) Find the highest charge among all patients in the array and display the

patient’s name and the charge.

(3 marks)

import java.io.File;

catch (Exc
END OF QUESTION PAPER

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

You might also like