Random Number Code

Recursion code example

Thread and Concurrency: What is concurrency
Binary Tree Code

Abstract Class and Interface
Explain why making instance variables public is not a good practice in object-oriented software engineering. Which is the alternative approach to making such variables public and what does it achieve? [8 marks]
Making instance variables public “reveals” effectively the way the actual class is implemented and allows the user of the class to mistakenly change these variables wrongly and introduce inconsistent state. The correct way to use classes is through their method interface which exhibiting specific “agreed” behaviour while the implementation of this behaviour should be opaque to the user. As such instead, of making instance variables public, we keep then private and introduce methods in the class interface which can manipulate them in a controlled “correct and consistent” manner.
Write the constructor and toString methods of class Point which extends the abstract class Shape, then of class Circle which extends class Point and then of class Cylinder which extends class Circle. You should demonstrate and explain how you achieve reusability by re-using the methods of the respective superclass. [12 marks]
Explain the concepts of inheritance and composition and discuss the benefits they bring to object-oriented software engineering. [7 marks]
Write a merge method of an OrderedList class which takes as argument an external ordered list and merges it with the ordered list instance variable, keeping it ordered. OrderedList inherits from List, which includes methods such as removeFromFront and removeFromBack, and adds an insert method which inserts an Object argument in the right position to the list. [10 marks]
What is a queue data structure? Show how a Queue class can be easily implemented through inheritance from a List class. [8 marks]
What is concurrent program execution and how can it be supported in Java? Present briefly two example applications for which concurrent execution is necessary. [7 marks]
Write a binarySearch method that searches through an integer array for a given search key. [12 marks]
What is the computational complexity of the binary search algorithm? Explain how you arrived at your answer. [6 marks]