IT2030 - Object Oriented Programming-Version F
IT2030 - Object Oriented Programming-Version F
00269
Machine No:
Durationi 3 Hours
November 2023
Instructions to Candidates:
• This paper contains four questions. Answer All Questions.
• Marks for each question are given on the paper. Total Marks: loo.
EE
• Create a folder on the Desktop with your student registration number and store all your
program files inside that.
• Create a separate Project for each question. The name of the project is provided in the
question.
• This paper contains 06 pages including the Cover Page.
• Zip the Student ID folder (Zipped folder also should be named with Student ID number).
• Upload the zipped folder to the correct link.
oo26\
Question 1 . (30 marks) .
This question is based on the Collection Framework and Generics.
a) Write a Java program that allows the user to manag-e a list of books in a library using a
Prompt the user to enter the titles of books one by one. Continue accepting book
titles as keyboard inputs until the user enters "done." Add each entered book title
book they want to remove. If the book title is found in the PriorityQueue, remove
it.Displayamessageindicatingwhetherthebookwassuccessfullyremovedornot,
in the case the title was not found. (06 marks) i
iii) Find and display the total number of books in the priorityQueue. -(02 marks)
iv) Print all the remaining book titles in the priorityQueue. (03 marks)
b) Create a Java program that manages the inventory of products using a HashMap. The
program should allow user to add products, update their quantities, remove products, and
view the current inventory.
i) Create a HashMap to manage the inventory, where the keys are unique product
codes (strings) and the values are objects representing each product. Each product
object should include the product name (string), the quantity in stock (integer), and
the price per unit (a double) (06 marks) \-
ii) Implement a method to add aproduct to the inventory. The method should take the
productcode,productname,quantity,andpriceperunitasparameters.Ifaproduct
with the same code already exists, update its details. (04 marks)
iii) Create a method to remove a product from the inventory based on the product code.
(02 marks)
c) In the main method, create a sample inventory with 5 products, and display the product
details. Then remove 2 products and display the remaining products again.
(03 marks)
a) You are going to implement the Abstract Factory- Pattern based on the scenario of
Vehicle factory that turns out Cars or Busses for the specified model. Refer the
Screenshot of the Console Output and the VehicleDemo class. You should implement
the rest of the other classes.
iv). Create Design 03 classes for Bus factory called (Volvo, Fuso, and TATA)
according to the singleton pattern. Each bus should have a displayvehicleo
method you must override.
`=, b) Now design three interfaces to IBus, Icar, and VehicleFactory to override common
behaviors.
i). Now design IBus and Icar interfaces and declare the displayvehicleo
operation in each.
(02 marks)
Hint: Rofer to the main program and package hierarchy given below
haA-lC: Fae5\AM\inlAQi44\binhiapiaeHH€ife29.2D23.1aecomo
Factory t`ms art Rollstrys ar
Fjrfury ttrms art Bcoz Car
Factory trms atrt ml Car
Factory tiims Out volvo 8Lis
Fatory tins otrt Fuse Bus
Factory tit ms ait TAIA utis
Package Hierarchy:
I oap-a-q1
> E 8drjara
> ill Brm.jRE
> E@ 8LEiFrdoryjarva
> in aradoryjanra
> in I-jama
> EE BLBjava
> ill kin.jima
> ill RoillsRftygiv
> in munjan.
> E V±atory.jRE
> in vehi~er.java
> in vrfujiFya
00269
Question 3 (20 marks)
This question is based on the Threads implementation.
You are tasked with simulating a resource allocation system for a multi-user environment. The
system manages a set of resources, and users can request to allocate and deallocate these resources
from the Resource Manager.
a) Create a class naned ResourceManager that manages a pool of resources. (02 marks)
i). Implement the requestResource() method where a user can request a resource. Ifa
resource is available, it is allocated to the user. If not, the user waits until a resource
becomes available. (04 marks)
ii). Implement the releaseResource() method where users can request to release the
resource they have acquired. (04 marks)
RE
b) Create a class called User that simulates a user. Each user should simulate users requesting
to acquire and release resources from a Resource Manager with a sleeping time of 1000
milliseconds in between acquiring and releasing. Each user needs to have a unique userld.
(06 marks)
c) The main class should initialize the ResourceManager object with 3 resources and 5
user threads, and the program should display messages indicating when users request and
release resources. Refer to the partial code of the Main class and the output below.
(4 marks)
public class Main {
public static void main(String[] args) {
int TResources = 3;
int TUsers = 5,.
ResourceManager rm = new ResourceManager (TResources) ,.
Sample Output:
Create an abstract class called "Person" with attributes as ID (int) and a name (String). This class
should also include a default constructor and an overloaded constructor to initialize these
attributes. Additionally, add an abstract method called "DisplayDetails()". Implement another
abstract class called "Course" class with attributes such as code (String) and a course name
(String). It should include a default constructor and an overloaded constructor to initialize these
attributes. Add an abstract method called "DisplaycourseDetailso".
The concrete "Student" class should be inherited from the "Person" class. It should have an
additional attribute as eurolledcourses which can hold a list to hold the enrolled courses. This
class should include a default constructor and an overloaded constructor to initialize the attributes.
Additionally, implement the following methods:
to display the student's details, including their ID, name, and the list of enrolled courses.
The concrete "Teacher" class should also be inherited from the "Person" class and have an
attributecalledcoursesTaughtwhichcanholdalistofcoursestheyteach.Thisclassshouldinclude
a default constmctor and an overloaded constructor to initialize the attributes. Additionally,
implement the following methods :
• Teachcourse(Course c): This method should allow teachers to add a course to th;ir list of
to display the teacher's details, including their ID, name, and the list of courses they teach.
Implement a class called "InstitutionManagementApp" with the main method. In the main
method, create 2 instances each of "Student" and "Teacher" classes and initialize their attributes
using the respective constructQrs. Allow 3 students to enroll in courses and teachers to add courses
they teach. Display the details of students, teachers, and courses using the provided methods,
taking advantage of the abstract class stmcture for common attributes and methods.