Professional Documents
Culture Documents
Universiti Teknologi Mara Final Examination: Confidential CS/APR 2008/CSC175/ITC160
Universiti Teknologi Mara Final Examination: Confidential CS/APR 2008/CSC175/ITC160
Universiti Teknologi Mara Final Examination: Confidential CS/APR 2008/CSC175/ITC160
INSTRUCTIONS TO CANDIDATES
1. This question paper consists of two (2) parts : PART A (15 Questions)
PART B (6 Questions)
4. Please check to make sure that this examination pack consists of:
1. The following methods will return a non-numeric value when they are called EXCEPT
A. charAt()
B. indexOf()
C. substring()
D. equalsIgnoreCase()
I. p u b l i c C a t ( i n t age){}
p u b l i c Cat(double weight){}
III. p u b l i c R a b b i t ( S t r i n g name, i n t a g e ) { }
public Rabbit(){}
A. II only
B. I and II
C. I and IV
D. Ill and IV
A. int x = c a l c V o l u m e ( 1 , 2, 3 ) ;
B. int x = calcVolume(1, 2.4, 3.70);
C. int x = calcVolume(1.1, 2.2, 3.3);
D. int x = c a l c V o l u m e d , 2 . 2 , 3) ;
A. 8.62
B. 8.6
C. 8.0
D. 8
A. inheritance
B. overloading
C. dynamic
D. abstraction
9. Given the the following code segment:
10. Which of the following is the definition for the constructor method used above?
A. constructor
B. accessor
C. mutator
D. processor
A. 0
1
2
3
B. 3
-5
C. 0
0
0
0
D. 1
2
3
4
14. Which of the following statements is the MOST APPROPRIATE to replace the statement
in l i n e 4 if the intention is to print the whole content of the array involved?
A. System.out.println(no[i]);
B. System.out.println(no[i] + no[i+l]);
C. System.out.println(no);
D. System.out.println("no");
A. I and II
B. I and III
C. II and IV
D. I, II and III
QUESTION 1
Write a program that reads a sentence and prints out the sentence in reverse order with all letters
in capital form.
Programming i s fun.
.NUF SI GNIMMARGORP
(7 marks)
QUESTION 2
System.out.print(title.substring(16, 22));
System.out.print(ingredients[3].charAt(1));
System.out.print(ingredients[3].charAt(3));
System.out.print(text.charAt(1));
System.out.print(title.charAt(13)) ;
System.out.print(title.charAt(1));
System.out.printIn(title.substring(12,15));
System.out.print(text.substring(7) ) ;
(4 marks)
QUESTION 3
Write overloaded methods named listofNumbers () for each of the following tasks:
a) Calculate and return the sum of all numbers that are greater than 5 from an array of
floating point values. The array is received as a parameter.
(3 marks)
b) Compute and return the average of all numbers in an array. The array and its size are
received as parameters.
(3 marks)
c) Return the position of the largest number stored in an array of integers. The array is
received as a parameter.
(3 marks)
QUESTION 4
Listed below are two classes named RectanguiarBox and RoundBaii to represent a
rectangular box and a round ball respectively.
// RectanguiarBox class
public class RectanguiarBox
// RoundBaii class
public class RoundBaii
{
public static final double PI = 3.142 r
private double radius; II in cm
public RoundBaii(double rad){ .-}
public double getRadius (){...}
a) Write a default constructor for the RectanguiarBox class which initializes the values for
all its data members to 0.
(1.5 marks)
b) Write a mutator method for the RectanguiarBox class which sets the values for all its
data members.
(2 marks)
c) Write the accesor methods for all data members of the RectanguiarBox class.
(3 marks)
e) Write a method named check () in the RectanguiarBox class. This method is used to
check whether a RoundBaii object can fit into the RectanguiarBox object or not.
Assume that the box can be closed with the ball inside. The RoundBaii object is
passed through the parameter. An appropriate message should be displayed for both
cases.
(4 marks)
QUESTION 5
Selera Marvellous Restaurant is a contemporary restaurant in town. The management would like
to have an electronic menu panel that will be placed beside each table in the restaurant. The
electronic menu will enable the customers to order the food or beverages from their seats without
having to wait for menu from the waitresses. They can order at their own time. The menu lists
food and beverages that this restaurant offers. The food can be categorized as Western,
Chinese or Malay food, while the beverages can be hot or cold drinks. Besides the categories of
food and beverages, the price list is also included in the menu. The customers only need to
touch on the screen pointing to what kind of food or beverage they want to order, and the number
of sets for each ordered food or beverage. Then the menu panel will display the table number
and the total price that the customers have to pay.
QUESTION 6
The following class is used to handle operation on a meal card used by the students at a
college's cafeteria:
//constructor
public MealCard (){...}
//mutator
public void setData (String name, int no, int pt) {...}
//retrievers
public String getName (){...}
public int getNo (){...}
public int getPoint (){...}
b) Write a method named addPointO that will be used to add points to the current
balance points. The points are entered by the user.
(2 marks)
ii) get all the values for the variables and store the data. For each card, initialize the
p o i n t to 100.
(5 marks)
iii) all students use their cards to have lunch at the cafeteria.
(3 marks)
iv) the students with the card number that starts with " 1 1 " add points to their cards.
(3 marks)