2021_FEB_CSC435.pdf (1)
2021_FEB_CSC435.pdf (1)
INSTRUCTIONS TO CANDIDATES
A. Robust
B. Portable
C. Distributed
↓
D. Insecure
A. method’s name
S
B. method signature
C. parameter’s name
D. data type of parameter
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");
/
C. public Car (int diameter, String model, String color)
{ steering = new Steering (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
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
&
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?
&
II. Book b = new Novel();
III. Comic c = new Book();
IV. Book b = new Comic();
S C.
D.
II and IV
III
//Methods
}
Which of the following is the correct header of the normal constructor for the above class?
15. The following statements are true about inheritance EXCEPT _________.
16. What will happen if you forget to close the stream of the I/O file?
/ 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
A. ot change what
8
B. t change what
C. change what
D. t change wha
import java.util.*;
public class Test
{
public static void main (String[] args)
{
Scanner s = new Scanner (System.in);
Number num = new Number ();
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)
i) Default constructor
ii) Mutator
iii) Accessor
iv) Printer
v) Processor
(11 marks)
//Methods:
//default and normal constructor
//accessors
//toString()
public double calCharges() {….}
}
//Methods:
//default and normal constructor
//accessors
//toString()
public double calCharges() {….}
}
ii) Processor method named calCharges() based on the abstract method in superclass
to calculate the charges of the activities for both WaterPark and WildlifePark
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:
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)
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:
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