-
(a)Using an Invoice class, show an example of method overloading using an invoice method with a parameter cost only and with two parameters cost and customerID. The methods simply return the cost. Note that both methods must be called from the main method. [5 marks]
(b)Write a Java program to traverse a Stack collection using the foreach loop and print out the values in the stack. The stack collection should have the following integer values: 10, 20, 30, 40, 50, 60, 70, 80, 90, 100. [10 marks]
(c)With the aid of a suitable diagram and explanation, show the different types of inheritance that exist. [10 marks]
-
(a)Write an abstract class named student. The student class should have the following attributes: name, sex, reg no and matric no. The class should have the following methods: getters and setters for the reg and matric no attributes. Then create a new undergraduate class to inherit the student class. [10 marks]
(b)(i)In detail, relate what you understand by inheritance in Object Oriented Programming (OOP) with inheritance in real life. [2.5 marks]
(ii)Differentiate between the "super" keyword and the "this" keyword in the context of inheritance in Object Oriented Programming (OOP). [2.5 marks]
-
(a)Write a Java program with a subclass that overrides a method and calls the superclass method. The code defines a hierarchy of classes in Java, with a Vehicle class and a Car class. Here's an explanation of what your code should look like: The Vehicle class is the base class with a method start(). When this method is called, it prints "Vehicle starting..." to the console. The Car class is a subclass of Vehicle. It overrides the start() method from the Vehicle class. The method that overrides should call the start() method of the overridden function and print "Car starting..." to the console. In the Main class, create an instance of the Car class named car and call the start() method on the car object. [10 marks]
(b)Expatiate the types of polymorphism that exist in Java and how they are implemented. [5 marks]
-
(a)Write a generic method named Bubbledescendingsort in a Java class. The class should also have a main method. The Bubbledescendingsort method should take a one-dimensional array as parameter and should return a sorted array. It should sort the array in descending order. The method should be called in the main method with an array passed to it. [10 marks]
(b)Explain how the Bubble sorting algorithm works and write the algorithm. [5 marks]
-
(a)Inheritance is a key concept in OOP. Expatiate four reasons why inheritance is needed in OOP. [6 marks]
(b)(i)Explain binary searching and write its recursive algorithm. [5 marks]
(ii)Explain linear searching and write its algorithm. [4 marks]
-
(a)Explain how the Selection sorting algorithm works and write its algorithm. [10 marks]
(b)List five (5) stack operations and state what they do. [5 marks]

