0% found this document useful (0 votes)
27 views

IT2030 - Object Oriented Programming-Version B

Uploaded by

it20046798
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

IT2030 - Object Oriented Programming-Version B

Uploaded by

it20046798
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

/ Student ID:

00108

Machine No:

Sri Lanka Institute of Information Technology

B.Sc. Honours Degree in Information Technology


Specialized in Information Technology

Final Examination (Computer Based)


Year 2, Semester 1 (2023)
Paper Version 8

IT2030 -Object Oriented Programming

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.

Instnictions to Candidates when submitting:


• Save all yourwork.
• Delete all umecessary files from each project folder (There should be 4 folders for 4
projects named as Questiono1, Question02, Question03 and Question04 inside your ID
folder, and each folder should contain the source code (.java files)) only.

• Zip the Student ID folder (Zipped folder also should be named with Student ID number).

• Upload the zipped folder to the correct link.


Question I
(20 mar
This question is based on the OOP concepts.

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

attributes, methods, and functionalities as follows.

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.

Save the project as Questiono1

Page 2 of 6
00108

Question 2 (30 marks)

This question is based on the Collection Framework and Generics.

a) Write a Java program that allows the user to manage a list of employee names using

AnayList. The program should perform the following tasks.

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

AnayList. (04 marks)

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)

Save the project as Question02A

b) Create a class called "Genericcalculator" with two generic methods as follows.


i) Define another generic method called calculateMaximum() that takes an array of
a numeric data type (Integer, Double, Float) as input and returns the maximum
value from array. (05 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

statements. (05 marks)

Save the project as Question02B

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

concurrently using Java threads.

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

Save the project as Question03

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).

i). Implement two interfaces lDrawableLines and lDrawableshapes and each


interface you should declare methods drawLines(String robotType) or
drawshapes(String robotType)
(02 marks)

ii). Then create 3 classes to design lines as DashLines, StraightLines, and


DottedLines and those classes should implement the IDrawableLines
interface and override all methods within the classes.
(06 marks)

iii). Similarly create another 3 classes Squareshapes, Triangleshapes, and


Circleshapes and those classes should implement the IDrawableshapes
interface and override the method as well.
(03 marks)

iv). Create an Abstract class Designselector and aggregate two interfaces


aDrawableLines,andlDrawableshapes),youshouldsetthosetwobehaviors
withusing"set"methodsandletdesignlinesorshapestomakethedecisionin
sub classes
(07 marks)

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.

Now implement the JapaneseRobot and ChineseRobot classes to draw lines


orshapesaccordingtothatformatandextendtheDesignselectorclassineach
to implement those behaviors.
(06 marks)
ii). Now modify all line classes (DashLines, StraightLine, DottedLine) and all
the shape classes (Squareshape, Circleshape, and Traingleshape)
according to the Singleton Pattern
(06 marks)

Page S Of 6
oolb&
Hinl. Rrfer to the main program and package hierarcky given below

Save the project as Question04

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());

beslgnselect®r chlneaeftobot = ing Chine8tot]ot( ) ;


chineseRohot.setiDra.fableshapes(Cirdeshapeg.getTnstore());
chin€seRat.art.designshapes();
chineseRohot.setiDraebleshapes(Squareshape8.gptJnstance());
`-
chineseRobot.designshapeg{);
chincseRohot.setiDrarableshapes(Tringleshqus.getrnstonce());
chineseRobot.designshapes();

±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

You might also like