IT2030 - Object Oriented Programming-Version B
IT2030 - Object Oriented Programming-Version B
00108
Machine No:
Duration: 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.
• 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).
Implement the necessary classes, along with their required attributes and methods, based on the
following description.
You have been assigned to develop a customer order processing system for an online store. The
system should consist of two classes, Order and Product. Each class should have specific
TheOrderclassshouldhaveanorderID(int),customername(String),orderdate(String),anda
queue to hold the selected products. The class should include a default const"ctor, an overloaded
constructor to initialize these attributes. Additionally, you are required to implement the two
methods below:
r-
• Addproduct(Product p): This method should allow the addition of selected products to the
order queue.
• Processordero:This method should display the order details and the llst of products
ordered.
TheProductclassshouldhaveaproductID(int),name(String),price(double),andstockquantity
(int). It should include a default constructor and, an overloaded constnictor to initialize these
attributes, and two methods, Reado and Display(). The Read() method should accept inputs for
the above-mentioned attributes through user inputs, and the Display() method should output their
values.
Implement a class called "OrderprocessingApp" with the main method. In the main method,
create 4 instances of the Product class and 2 instances from Order class. Input order details using
`u
the overloaded constmctor for the Order class and product details using the Read() method of the
Productclass.AddproductstotheorderusingtheAddproduct()method.Displaytheorderdetails
and the list of products in the order using the Processorder() method.
Page 2 of 6
00108
a) Write a Java program that allows the user to manage a list of employee names using
i) Create an empty AnayList of strings to store employee names. Then prompt the
user to enter the names of employees one by one. Keep accepting names as
keyboard inputs until the user enters "done". Add each entered name to the created
ii) Once the user finished entering the names, ask the user to enter the name of the
employee they want to remove. If the employee's name is found in the ArrayList,
remove it. Display a message indicating whether the name was successfully
removed or not in the case if the name was not found. (06 marks)
iii) Findanddisplaythe totalnumberofemployees inthe ArrayList. (02 marks)
iv) Print all the remaining employee names in the AnayList. (03 marks)
ii) Define a generic method called calculateproducto that takes an array ofa numeric
data type (Integer, Double, Float) as input and returns the product of i'ts elements.
This method should multiply all the elements in the array and return the result.
(05 marks)
ili) Write a class called "MainApp" which contains the main method. Create two
objects from the Genericcalculator class where the first object accepts an Integer
type array for the above two methods and the second object accepts a Double type
of array for the above two methods. Display the results using proper printing
Page 3 of 6
Question 3
This question is based on the Threads implementation.
You have two types of vehicles, "Car" and "Bike," that need to be tested on a racetrack
a) Create a class called "Car" which can simulate racing by displaying "Car is racing"
five times, each time followed by a 500-millisecond delay to simulate a racing lap.
(06 marks)
Create another class called "Bike" which can simulate racing by displaying "Bike is
racing"fivetimes,eachtimefollowedbya500-milliseconddelaytosimulatearacing
lap.
(06 marks)
Implement another class called " RaceRunner" with a main method. In the main ,
method, create one thread object each from car and Bike classes. Start both threads -
to simulate the concurrent racing of a car and a bike. (05 marks)
d) In the execution ensure that the car completes its race before the bike starts.
(03 marks)
Hint: Rof;er to the sample output given below
Sample Output:
Car is racing
Car is racing
Car is racing
Car is racing
Car is racing
J
Bike is racing
Bike is racing
Bike is racing
Bike is racing
Bike is racing
Page 4 of 6
00108
(30 marks)
Question 4
This question is based on the Design Patterns implementatlon.
a) You are going to implement the Strategy Design Pattern based on the scenario of
Robots usage for Textile industry for different patterns designing purpose in Japan
and China. These robots can design either lines (Dash lines, dotted lines, and Straight
lines) or shapes (Square, Circle, and Triangle).
b) Now design two robots from two different countries they can let to show rob?t type
either Japanese or Chinese and accordingly it should display the outputs as given in
the TextilelndustryDemo.
Page S Of 6
oolb&
Hinl. Rrfer to the main program and package hierarcky given below
Main Program:
E) Conde H
1 package oap.exa-.q2;
2 I X *! I
3 public class Te)ctilelirfustryDeco {
4
LTEFE¥EFiii=EiiEEEERE+EEEEEIE
Or- ODtted tl.ecs on cJathes try J_a Robot
Or- Str]lcht Ll--S on clothes by ]-S Robot
public static void rain(String[] argg) { or- Circles er. clothes dy a.± ftobot
or- Sq`i.res on clothes try cll± Bobat
or- Trianglcs co cletbes dy chicece aobet
besigriselector japaneseRobgt = rrty Jj]paneseRobot( );
japariesckohot. (DashLineg.getln5tance());
japan.seRobot.
japane3eJtobct. (DuttedLines.getlnsran<:.a());
±3)
E=.I
• Package Hierarchy:
v 4 oap.examq2
> Ea chine±
> in Chckflrapegiv.
> fi DashLhajan
> RE Defa~or.java
> Ea DunedLinc5.jarya
> EE Hiranabhiingiva
> E uhawab±giva
> E japanesdthtgiva
> a Squanshap6.java EE
> E StTaightLhajara
> E} ~TrdhetryDtho.java
> E) hangkfropesgiva
Page 6 of 6