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

2021_FEB_CSC435.pdf (1)

This document is a final assessment paper for the Object Oriented Programming course (CSC435) at Universiti Teknologi Mara, dated February 2021. It consists of two parts: Part A with 20 objective questions and Part B with 3 descriptive questions. The paper covers various topics related to OOP concepts, Java programming, and file I/O operations.

Uploaded by

Noor Athirah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

2021_FEB_CSC435.pdf (1)

This document is a final assessment paper for the Object Oriented Programming course (CSC435) at Universiti Teknologi Mara, dated February 2021. It consists of two parts: Part A with 20 objective questions and Part B with 3 descriptive questions. The paper covers various topics related to OOP concepts, Java programming, and file I/O operations.

Uploaded by

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

CONFIDENTIAL 1 CS/FEB 2021/CSC435

UNIVERSITI TEKNOLOGI MARA


FINAL ASSESSMENT

COURSE : OBJECT ORIENTED PROGRAMMING


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

INSTRUCTIONS TO CANDIDATES

1. This question paper consists of 2 parts: Part A (20 Objectives)


Part B (3 questions)

2. Answer ALL questions

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


This examination paper consists of 10 printed pages

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


2
CONFIDENTIAL CS/FEB 2021/CSC435

PART A (40 MARKS)

1. Which of the following term is NOT referring to an advantage of using OOP?

A. Robust
B. Portable
C. Distributed

D. Insecure

2. Overloaded methods must have the same______.

A. method’s name
S
B. method signature
C. parameter’s name
D. data type of parameter

3. By using an I/O text file, ___________________.

A. data are read and saved as objects


B. data are read and saved as strings
/
C. data are read and saved as byte
D. data are read and saved as database

4. Which of the following is NOT declared using a primitive data type?

A. char c;
B. byte c;
/ C. String s;
D. double d;

5. The following Java statement will display the following output EXCEPT _______

123
456

/
A. System.out.println (123 + 456);
B. System.out.println ((100+23) + "\n456");
C. System.out.println ("123\n456");
D. System.out.println (123 + "\n456");

6. A private modifier of data member in a class can be accessed ______________.

A. by the methods of any class


B. directly from the main program
C. by the constructor of any client class
&
D. directly by the methods of the class
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
3
CONFIDENTIAL CS/FEB 2021/CSC435

7. Which of the following constructor has a composite object?

A. public Car (int diameter, String model, String color)


{ this.diameter = diameter;
this.model = model;
this.color = color; }

B. public Car (int d, String cm, String cc)


{ diameter = d;
model = cm;
color = cc; }

/
C. public Car (int diameter, String model, String color)
{ steering = new Steering (diameter);
this.model = model;
this.color = color; }

D. public Car (int diameter, String model, String color)


{ super(diameter);
this.model = model;
this.color = color; }

8. Which of the following extension name that represents a Java bytecode file?

A. .java
/
B. .class
C. .exe
D. .obj

9. ___________ consists of a set of separate programs for developing and testing Java
program, each of which is invoked from a command line.

A. Java IDE
& B.
C.
Java JDK
Java API
D. Java language specification

10. Which of the following statements are TRUE about constructor?

I. Constructor name matches with class name


II. Constructor can be named with any valid identifier
III. Constructor does not associate with return type

x
IV. Constructor can be overloaded

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

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


4
CONFIDENTIAL CS/FEB 2021/CSC435

11. What does the new Java keyword do?

A. It uses to declare an object


B. It gives a new object name
C. It holds a memory address

&
D. It allocates the needed memory for a new object

12. Given the superclass named Book and two subclasses named Novel and Comic. Which
of the following declaration is valid?

I. Book b = new Book;

&
II. Book b = new Novel();
III. Comic c = new Book();
IV. Book b = new Comic();

A. I, II, III and IV


B. I, II, IV

S C.
D.
II and IV
III

13. Which of the following statement is TRUE?

A. Every method must end with a semicolon.


B. Every comment line must end with a semicolon.
C. Every line in a program must end with a semicolon.
/D. Every statement in a program must end with a semicolon.

14. Given the following template of a class definition:

public class Staff


{
private String name;
private String department;
private double salary
final double rate = 0.25;
final double allowance = 250.0;

//Methods
}

Which of the following is the correct header of the normal constructor for the above class?

A. public Staff (String name, String department, double salary,


double rate, double allowance)
&B. public Staff (String name, String department, double salary)
C. public Staff (double rate, double allowance)
D. public class Staff (String name, String department,
double salary)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


5
CONFIDENTIAL CS/FEB 2021/CSC435

15. The following statements are true about inheritance EXCEPT _________.

A. the root class of all classes is Object


B. subclasses inherit all methods and fields of superclass except the super class
constructors
& C. subclasses inherit all constructors from superclass by default
D. subclasses may contain additional fields and methods of its superclass

16. What will happen if you forget to close the stream of the I/O file?

A. Conflicts of I/O streams will happen


B. The program will be halted
C. Could not display the output
I D. Some data may get lost due to data caching

17. Given the following statement:

“It is used to represent information shared by all instances to represent collective


information about the instances”.

Which of the following that describes about the above statement?

/ A.
B.
Static field
Static method
C. Instance field
D. Instance method

18. Which of the following modifier on members of a class that is not accessible to another
class in different package but is accessible to any subclass in the same package?

A. public
B. private
C
C. protected
D. Use default modifier

19. Which of the following OOP concepts can perform a single action in different ways?

A. Abstraction
B. Encapsulation
C. Inheritance

/ D. Polymorphism

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


6
CONFIDENTIAL CS/FEB 2021/CSC435

20. Given the following statements:


0
123456789
String quote = "You cannot change what you are, only what you
10"
234567898 /
Do";
System.out.println (quote.substring(9, 22));

A. ot change what
8
B. t change what
C. change what
D. t change wha

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


7
CONFIDENTIAL CS/FEB 2021/CSC435

PART B (60 MARKS)

QUESTION 1 (15 MARKS)

Consider the following Test class:

import java.util.*;
public class Test
{
public static void main (String[] args)
{
Scanner s = new Scanner (System.in);
Number num = new Number ();

System.out.println(“Enter a number “);


int n = s.nextInt();

num.setNumber(n);
num.displayNumber();

if (num.isEven())
System.out.println(num.getNum() + “ is even number”);
else
System.out.println(num.getNum() + “ is odd number”);
}
}

a) How many attributes that possibly involved in the Number class and give the data type of
those attributes?
(2 marks)

b) State the method name for this Number class for each of the following category:

i) Mutator
ii) Accessor
iii) Processor
iv) Printer
(2 marks)

c) Write the definition for each of the following:

i) Default constructor
ii) Mutator
iii) Accessor
iv) Printer
v) Processor
(11 marks)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


8
CONFIDENTIAL CS/FEB 2021/CSC435

QUESTION 2 (30 MARKS)

Given the following super class and subclasses:

public abstract class ThemePark


{
String name; // customer's name
String icNo; // customer's identification card number
boolean member; // either member or nonmember of the
// theme park
//Methods:
//default and normal constructor
//, //accessors
//toString()
public abstract double calCharges(); //calculate the
//charges
}

public class WaterPark extends ThemePark


{
String activity; // surfBeach,waterRide or other

//Methods:
//default and normal constructor
//accessors
//toString()
public double calCharges() {….}
}

public class WildlifePark extends ThemePark


{
String category; //child or adult
boolean isTrain; //use train or not

//Methods:
//default and normal constructor
//accessors
//toString()
public double calCharges() {….}
}

a) Write the following method definition:

i) Normal constructor for both subclasses.


(6 marks)

ii) Processor method named calCharges() based on the abstract method in superclass
to calculate the charges of the activities for both WaterPark and WildlifePark

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


9
CONFIDENTIAL CS/FEB 2021/CSC435

classes for a single ticket. Customers who are members of the ThemePark will be given
a special discount of 25% for every ticket charge.
The details of ticket charges are given in Table 5.1 and Table 5.2:

Table 5.1 Details of ticket charges for Water Park


Activity Cost (RM)
Surf Beach 40.00
Water Rides 30.00
Other 15.00

Table 5.2 Details of ticket charges for Wildlife Park


Category Cost (RM)
Adult 35.00
Child 20.00

An extra RM5 will be charged, if the customer uses the train for Wildlife Park.
(9 marks)

b) Write code fragments in the application/driver class that can perform the following tasks:
(Assume all relevant methods have been defined in all the three classes above)

i) Declare an array of object named tp to store various types of theme park where the size
of array is entered by the user.
(2 marks)

ii) Assuming data has been stored in this tp array, calculate and display the total charges
of every WaterPark and WildlifePark ticket respectively.
(5 marks)

iii) Print the list of adult customers in the Wildlife park and the total number of adults,
followed by the list of child customers in the Wildlife park and the total number of children.
(8 marks)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


10
CONFIDENTIAL CS/FEB 2021/CSC435

QUESTION 3 (15 MARKS)

Given the following text file named Residence.txt in Figure 1 that contains the data about
the owner of the apartment. The data is comprised of owner’s IC number, name, unit, level and
block of apartment.

Figure 1: Residence.txt

Write a complete Java program using the file I/O operation that can perform the following tasks:

a) Read all records from text file named Residence.txt in Figure 1

b) Store all data into the following output files according to gender:

• If the owner is a male, then write the data into file named male.txt as shown in Figure
2
• If the owner is a female, then write data into file named female.txt as shown in Figure
3

The gender can be determined based on IC number where the last character of IC number
represents the gender. if it is an odd number, then the owner is a male; otherwise the owner
is a female. Both sample of output files are shown below:

Figure 2: male.txt

Figure 3: female.txt

c) Close all file streams in used.

d) Apply exception handling mechanism in the program


(15 marks)

END OF QUESTION PAPER


© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

You might also like