Professional Documents
Culture Documents
COMPUTER SCIENCE
WESTIVILLE CAMPUS
Practical II
Examiner: Mr E. Jembere
Duration: 0pen
Marks : 100
Instructions
1. *Write a java program to read in a Java source code file and count the occurrence of each keyword in
the file, but don’t count the keyword if it is in a comment or in a string literal.
[20 marks]
2. **Write a program that reads words from a text file, counts the occurrence of each word in the file, and
stores words and their frequencies in a map and displays the words and their corresponding frequencies
in the order of their frequency. In the storage of the word occurrences, the words should remain the keys
and the frequencies should remain the values. Please note that you are not expected to create the class
“WordOccurence” as was expected in Practical I.
[30 marks]
3. *Write a program that reads the data in the file marks.csv provided on Moodle and store the data in a
data structure that enables efficient retrieval of all the modules that a given student has attempted and
1|Page
their corresponding marks (see Figure 1). The program should read the file once, through a single pass
through the file. Thereafter all queries for student marks should be done on the data structure. The
program should have GUI such as the one shown in Figure 1 that allows the user to pass a student
number as query for the student’s marks.
[20 marks]
4. **(Postfix notation) Postfix notation is a way of writing expressions without using parentheses. For
example, the expression (1 + 2) * 3 would be written as 1 2 + 3 *. A postfix expression is evaluated
using a stack. Scan a postfix expression from left to right. A variable or constant is pushed into the
stack. When an operator is encountered, apply the operator with the top two operands in the stack and
replace the two operands with the result. The following diagram shows how to evaluate 1 2 + 3 *.
Write a program to evaluate postfix expressions. Pass the expression as a commandline argument in
one string.
[30 marks]
----------------------------------------------------------------------------------------------------------------
2|Page