Professional Documents
Culture Documents
FA Ogos22
FA Ogos22
INSTRUCTIONS TO CANDIDATES
2. Answer ALL questions in the Answer Booklet. Start each answer on a new page.
3. Do not bring any material into the examination room unless permission is given by the invigilator.
QUESTION 1
class Queue {
public Queue () {...}
public enqueue (Object obj) {...}
public Object dequeue () {...}
public boolean isEmpty(){...}
public String toString () {...}
}
//Line 1
int xy = 0;
while(!q1.isEmpty()){
Object obj=q1.dequeue();
xy = xy + (int) obj;
if (xy % 2 == 0)
q2.enqueue(xy);
q3.enqueue(xy);
}
//Line 2
}
}
a) Draw diagrams of q1, q2 and q3 to represent the content in these data structures at Line
1 and Line 2. Please label the front and the rear of the data structures.
(5 marks)
//normal constructor
//accessors: getName(), getID(), getCategory(),
//getIcNo(), getAmount();
//printer: toString();
}
Assume that many ZakatUiTMRecepient2021 objects have been created and added to
the ZakatUiTM queue.
i) Display the total amount of UiTM zakat distribution in the year 2021. Store the original
data in a temporary queue.
(5 marks)
ii) Display the number of Zakat UiTM recipients. Store the original data in the temporary
queue.
(5 marks)
c) Display the number of Zakat UiTM recipients according to the category. For each
category, display the highest and lowest amount received by the recipient.
(10 marks)
QUESTION 2
a
)a) Given the following:
1) ( A + B ) $ ( C + D ) – E
2) A – ( B + C ) * D + E / F
(5 marks)
ii) Given an infix expression as:
Z=(M*E–L)+(A–K/U)
(1 mark)
(5 marks)
iii) Given a newStack diagram as follow. Write a program fragment to display the
output S A T U from the stack.
S
A
T
U
N
newStack
(4 marks)
Assume that all data have been inserted into a stack called vacStack.
i. Remove vaccine Pfizer which produced in year 2021 and insert into pfStack,
otherwise, insert into tempStack. Then, return back from tempStack into
vacStack.
(5 marks)
ii. Find and display the average price for vaccine Sinovac. All data in the original stack
should remain.
(5 marks)
iii. Search and replace a new price for vaccine AstraZeneca which its vaccine number
is 007 to RM 1999.00. Then, display the information. All data in the original stack
should remain.
(5 marks)
theStack.pop();
tempStack.push(theStack.peek());
theStack.pop();
tempStack.push(theStack.peek());
theStack.pop();
tempStack.push(theStack.peek());
QUESTION 3
(P - Q / R) * (S + T * P $ T)
ii) Traverse the tree in (i) using PREORDER and POSTORDER traversal.
(5 marks)
class Disease {
private String diseaseName;
private double percentDeath;
private int year;
class TreeNode {
Disease data;
TreeNode left, right;
/*** Definition of the other methods ***/
}
class BSTDisease {
TreeNode a;
public BSTDisease(){…} //constructor
public void printAll() {…}
public void calTotByYear(int) {…}
public void printBySpesific(){…}
public double calByDisease(String)
/*** Definition of the other methods ***/
}
The following table shows the data for five principal on causes of medically certified death
in Malaysia from 2018 until 2020.
Draw a Binary Search Tree and write the definition for display methods as below:
(4 marks)
ii. Method printAll() and its recursive method to display the details of disease in
descending order according to death percentage.
(5 marks)
iii. Method printBySpesific() and its recursive method to display the details of
disease with death percentage more than 10%.
(6 marks)
c) Write the definition for methods that are passed values year and disease through its
parameter as below:
(5 marks)
(5 marks)