Professional Documents
Culture Documents
CSC508 - Example Questions
CSC508 - Example Questions
NF AutoExtremeCar is a car company in Penang. This company sells good quality cars
from various models and keeps the details of its cars using sequential lists (ArrayList). The
following are the ADTs of Car and ArrayList.
// normal constructors
// mutators and accessors
// toString() printer
}
// To get TEN (10) car objects from user and insert into carList
for (int i = 0; i < 10; i++)
b) Update the car plate number from “DDC14” to “DDE14”. After updated, display the
car particulars with that new plate Number.
(3 marks)
c) Remove all car objects that were manufactured in year 2020 and insert them into
another ArrayList named newList.
(3.5 marks)
1
CONFIDENTI CS/JUL
public class
CounterService{ private
String waitID;
private String caterogy; //Personal, Business
private char serviceType; //A-Banking, B-Other services
public class
Queue{ public
Queue();
public void
Given a Queue object named customerList has been created and inserted with customer
details. Write java program segments to perform the tasks below.
d) Copy customer details from the customerList into two (2) Queue objects named
waitListA and waitListB according to the service type as in the following table.
The original elements are remained in the customerList using a temporary
Queue object.
(6 marks)
(4 marks)
2
CONFIDENTI CS/JUL
a) Write a program fragment which uses a stack to convert a decimal number to its
equivalent octal representation. You could use the following example as a guideline.
For example, to convert 825 to octal form, manually this is how the conversion is
done: 825 is divided by 8 continuously, then the remainder of each division is taken in
reverse order to form the octal number.
Division Remainder
i. 825 / 8 = 103 1
ii. 103 / 8 = 12 7
iii. 12/ 8 = 1 4
iv. 1/8 = 0 1
Thus, the octal form for 825 is 1471 (the remainder in reverse order)
(6 Marks)
b) What is the output of the following program? (Assume no error in the program)
System.out.print (s2.top() + “ “ );
s2.pop ();
}
System.out.println ();
}
public static void mystery (StackClass s, StackClass t){ while(!s.isEmptyStack(
t.push (s.top ()) ; s.pop ( ) ;
}
}
} // end main
(4 Marks)
3
CONFIDENTI CS/JUL
c) Given the following method 'foo', determined the returned value of foo(22,8). You
MUST show the tracing of this recursive function.