Mid Semester Test Question Paper ICT502 Sample
Mid Semester Test Question Paper ICT502 Sample
Student ID:
INSTRUCTIONS TO CANDIDATES:
1. Write your Student ID in the box provided above.
2. Use the reading time to study the question paper but do not begin writing until
instructed.
3. Candidates may seek clarifications with invigilators/examiners during the reading time
only.
4. Candidates are not allowed to leave the examination room within the first 30 minutes of
the exam, or within the last 15 minutes of the exam.
5. Students should attempt ALL questions unless otherwise stated.
6. Write all your answers through LMS editor.
1. What is the value of variable a after the following statements are executed?
a = 38;
a = a + 52;
a = a * 3;
a = a / 4;
[2 marks]
2. Assuming that a Random object has been created called generator, what is the
range of the result of each of the following expressions?
generator.nextInt(50);
generator.nextInt(32) + 2; [2 marks]
3. Write a class named Book with fields for a book's title, author, and number of pages.
Include get and set methods for each field. Include an equals () method that
indicates two books are equal if they have the same title, author, and number of
pages. Write a toString() method to print the book's details. You need to write
two(2) constructors for this class: an empty constructor and a constructor to
initialize all fields. [10 marks]
4. Now write a testBook class to instantiate two books by following the information
below:
a. Instantiate book1 with no information. Set title to "The Great Gatsby", author
to "F. Scott Fitzgerald", and number of pages to 218 using the setter
methods.
b. Instantiate book2 by passing title, author, and number of pages of your
choice.
c. Print book1 and book2 information.
d. Compare book1 and book2 if they are the same or not. Use equals ()
method to compare and print the result.
[2 + 2 + 1 + 1 = 6 marks]