-
(a)Write a Java program to calculate and display the area of an equilateral triangle. Note that the area of an equilateral triangle is given as , where is the length of any side. The length of the side should be gotten from the user. [5 marks]
(b)Libraries have been tracking their inventory for centuries, originally using card catalogs, and more recently, electronic inventories. Modern libraries have web-based catalogs that can be queried from individuals' homes. The local librarian has asked you to write a new card catalog program because their ancient DOS-based program is ugly and out of date. You know that catalogs contain lists of books. People search them to find books on certain subjects, with specific titles, or by a particular author. Books can be uniquely identified by an International Standard Book Number (ISBN). Each book has a Dewey Decimal System (DDS) number assigned to help find it on a particular shelf. But on meeting with the librarian, further details were explained. She told you that this is a good start, but libraries don't serve only books; they also have DVDs, magazines, and CDs, none of which have an ISBN or DDS number. All of these types of items can be uniquely identified by a UPC number. You reminded the librarian that they have to find the items on the shelf, and these items probably aren't organized by UPC. The librarian explains that each type is organized in a different way. The CDs are mostly audio books, and they only have a couple of dozen in stock, so they are organized by the author's last name. DVDs are divided into genre and further organized by title. Magazines are organized by title and then refined by the volume and issue number. Books are, as you had guessed, organized by the DDS number. From the details given above, identify potential objects and their respective attributes. [10 marks]
(c)Write a Java program to print out the flag of Nigeria as shown in Figure 1 below using a nested loop. [7 marks]
****====****
****====****
****====****
****====****
Figure 1. Map of Nigeria with * and =
(d)Explain what you understand by the following concepts in Object Oriented Programming and give suitable examples: (i) Inheritance (ii) Polymorphism (iii) Abstraction (iv) Encapsulation [8 marks]
-
(a)What are the different types of variables in Java? Explain the scope and purpose of variables with examples. [6 marks]
(b)Write a Java program that computes (i) Area of a rectangle (ii) Perimeter of a rectangle. Note: Area of a rectangle is given as A = L * W and perimeter of a rectangle is given as P = 2(L * W), where A = Area, L = Length, W = Width, P = Perimeter. [8 marks]
(c)State what each of the methods is used for: (i) Math.max(x, y) (ii) Math.min(x, y) (iii) Math.sqrt(x) (iv) Math.abs(x) (v) Math.random() (vi) Math.pow(a, b) [6 marks]
-
(a)Program flow in structured programming is controlled exclusively by three forms of control. List the three (3) forms of control with an example each. [6 marks]
(b)Write a program in Java to find the area of a scalene triangle using Heron's formula. The input is to be gotten from the user. The area of a scalene triangle with sides , and is given as , where . [7 marks]
(c)Write a Java program to accept elements for a 4×4 matrix and print out the diagonal elements using a for loop. [7 marks]
-
(a)What is the use of the following in the process of compiling and running a Java program? (i) IDE (ii) .java file (iii) JDK (iv) JRE (v) .class [7 marks]
(b)Write a Java program that takes a number as input and prints its multiplication table up to 10. [6 marks]
(c)Write a prototype for a function named Area, which returns the area of an annulus. The method takes two parameters a and b, where a is the inner radius and b is the outer radius. Write a main method to call the function created. The area of an annulus is given as . [7 marks]
-
(a)Write a Java program to create an object called "myObj", assign a value to the variable j and print the value of j. [5 marks]
(b)Define the following: (i) Access modifier (ii) Constructors [5 marks]
(c)(i)List five (5) access modifiers and their description in a tabular form. [5 marks]
(ii)Explain the role of the import keyword in Java and why it is necessary when working with packages. [2 marks]
(iii)What is the difference between importing a single package and importing an entire package? Provide the correct syntax for both cases. [3 marks]

