IEEi 0$076
Student ID:
Machine N 0:
Sri Lanka Institute of Information Technology
B.Sc. Honours Degree in Information Technology
Specialized in Information Technology
Final Examination (Computer Based)
EEzfi
Year 2, Semester 1 (2023)
Paper Version D
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.
:.gr • 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 08 pag'es including the Cover Page.
Instructions to Candidates when submitting:
• Save all your work.
• Delete all unnecessary 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 naned with Student ID number).
• Upload the zipped folder to the correct link.
Question 1
(20 marks)
This question is based on the Collection Framework and Generics.
a) You should implement an array list of Students and Lecturers and use one Generic class
called Genericperson to display elements in both array lists. Please refer the
GenericpersonDemo Test class and its execution output to fine-tune your results.
15 ,public class GenericpersonDeno {
16
public static void main(String[] args) {
ArrayList<Student> students = new ArrayList<>();
students.add(new Student("STD1111-, 6));
students.add(ne-r Student(-STD2222", 7));
students.add(new Student( "STD3333-, 12));
students.add(nei. Student(-STD44-44". 11));
students.add(new Student(-STD5555", 10));
EH
ArrayList<Lecturer> lecturers = new ArrayList<>();
lecturers.add(new Lecturer("EHPOOcO-, -IT-));
lecturers.add(new lecturer(-EHP1111", "SE-));
lecturers.add(nei. Lecturer("EHP2222-, "CSN-));
lecturers.add(nell Lecturer("EMP3333., "EE-));
lecturers.add(new Lecturer(-Ellp4444-, -IS-));
ee.n£|ifleLEfj?`p`. genericperson = ne.. ~q§ngl:ic,Pfls`p_n` ( ) ;
ge`EL§TigB!gr^s,9,B„d,£5i2J,exE.I.gEen.t.§..`(§£tt`¢`eHt`§jj
ge.p.g.pi.€,P.e.T.§g`gNt`d`i5`p`±`eyE`lgE§g±^£fl,e,cJ;j]„p,g,£S..),;
i) Corcole ae
< teim iiiated > GenchcPersonDeiiro Application]
b tudent = STD1111, Grade = 6
Student = STD2222, Grade = 7
Student = STD3333, Grade = 12
Student = STD4444, Grade = 11
Student = STD5555, Grade = 10
lecturer
Lecturer
Lecturer
Lecturer
Lecturer
i) Create Implement an interface Iperson and declare the method displayDetails()
should return the output in string type. (02 marks)
ii) Create a class called student and implement the two properties called studetlD
(String) and grade (int) and values should be assigned through the overloaded
constnictor.
(02 marks)
®®S?6
L% iii) Implement the Iperson interface in the Student class and override the method
displayDetails() to print the student lD and the grade. (02 marks)
iv) Create a class called Lecturer and implement the two properties called
employeelD (String) and department (String) and the values should be assigned
through the overloaded constructor. (02 marks)
v) Implement the Iperson interface in the Lecturer class and override the method
displayDetails() to print the employeelD and the department. (02 marks)
vi) Now create the generic class called Genericperson and implement the method
displayElements should support passing generic array list (either Lecturers array
list or Students array list). The displayElement§O method should have an iteration
and within the iteration, the each element should call the displayDetails() method
to print the Lecturer and student details as per the given output. (05 marks)
-`
Save the project as QuestionolA
b) You should create a class called AscendingTable and that should store elements as key,
value pairs. Keys should be stored according to the Ascending order. Implement the
display() method that should print keys and values according to the ascending order. Refer
the GenericDemo Test class and console output to adjust your results accordingly.
(05 marks)
8 ;prbllc cl.ae G4peericDco {
9:
publit st.rtlc `fl.ad raln{Strlng[] angs) {
AscendingTal>le<Iuteger, string> ryTal.le -B.a. ^scendlngTatllcK>( ) ;
ryTable.add(4®, -dad-);
j`J ryTable.add(1o, -aaa.);
ilyTable.Odd(3e, -ccc-);
ryTable.add(2o, -bob-);
AscendingTable<Integer, Double> ryTableD a rm-AscendingTable<>();
tyTalileo.add(co, 1o.123);
ryTableo.add(3®, 23.456);
ryTableo.add(20, 34.S67);
nyTableo.add(i©, 45.678);
AscendingTable.diLspLqy(tyTable);
AscendingTable.disptqy(nyTableD);
cterminatE`d> GenericDemo [fara Aitlicationl a 1JLO_20\l)ir^iay3wL®te Cep 2. 2D11 .2Z7as 4±
10 aea
2e bbt'
30 CCC
40 dBd
10 45 . 678
20 34 . 567
30 23 . 456
cO 1®-123
Save the project as QuestionolB
Question'2 (20 marks)
This question is based on the Threads implementation.
You are tasked with simulating the Producer Consumer chain in a factory. The factory uses Iron,
Wood and Cement to make their products. The raw materials are supplied by different suppliers.
Once raw materials are received it should increase the inventory and each time a product is
produced, it should reduce 1 Iron, 2 Wood and I Cement from the inventory.
Ifrawmaterialisunavailabletheproductionlineshouldbehalteduntilthesuppliesarrive.Sample
output is given below.
a) Create 3 classes called Supplierlron, Supplierwood, and Suppliercement that handle
the supply of raw materials. Each class should supply I material every 600 milliseconds.
(o6 marks) L
b) Create a ProductionLine class that handles production with a rate of I product every 1000
milliseconds. (04 marks)
c) Create Factorysimulation Class that maintains the inventory and handles the handles the
production based on the available inventory. ( 10 marks)
Save the project as Question02
Sample Output:
bupplied 1 Wood. Wood Inventory: 1
Supplied 1 Cement. Cerpent Inventory: 1
Waiting for supplies. . .
Supplied 1 Iron. Iron Inventory: 1
Waiting for supplies. . .
Supplied 1 Iron. Iron Inventory: 2
Waiting for supplies. . .
Supplied 1 Lfrod. Itood Inventory: 2
Supplied 1 Cement. Cement Inventory: 2
Product produced. Iron: 1, Wtod: 0, Cement: 1
Supplied 1 Cement. Cement Inventory: 2
Supplied 1 Wood. Wood Inventory: 1
Supplied 1 Iron. Iron Inventory: 2
Waiting for supplies. . .
$0®76
Question 3 (30 marks)
This question is based on the Design Patterns implementation.
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.
i). Implement Vehicleproducer class that retuns either CarFactory or
BusFactory outputs through getvehicleo operation. Refer the screenshot in
Demo class.
(02 marks)
ii). Design CarFactory and BusFactory classes according to the Singleton
EE
Pattern and let getModel(String vehicle) select the factories.
(06 marks)
iii). Design 03 classes for Car factory called (BMW, Benz, and RollsRoys)
according to the singleton pattern. Each car should have a displayvehicleo
method you have to override.
(03 marks x 03 = 09 marks)
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. (o3 marks x o3 = 09 marks)
iEEi
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.
(01-mark x 2 = 02 marks)
ii). Design vehicleFactory as an Interface and declare the getModel operation to
select vehicle option either Bus or Car
(02 marks)
Hint.. Refer to the main program and package hierarchy given below
Save the project as Question03
Main Program:
3 public class VehicleselectiorDedro
4-
; ::::::: :=a::: f:::: S::.i: # : :::::;
public static void .aim(String[] args) {
((Icar) Vchicleproducer. getvchtcte(C") getHbdel(.RollsRoys-)).display`/chicle();
( (Icar) Vehicleproducer. get.Vehtc fe(Cap) getMbdel(-Benz-)).dispLayvehicle();
( {Icar) Vchicleproducer. getvehtc fe(C") getModel(-BW-)).displayvchicle{);
( (IBus ) Vehicleproducer. getvchtcte(Bus) get"el(-Volvo-)).displayvehicle();
( (IBus ) Vchicleproducer. getveAtcLe(Bus) gethodel(.Fuso-)).display`/ehicle{);
( (IBiis} Vchicleproducer. getychtcfe(Bus) getModel(-TATA-)).display`/chicle();
Factory tims a.Jt Ousfioys 29. 2023, 1~
Fdtory tims out echz Car
Factny t`ms ol.t tHI Car
Facter]r ttms aert Valve Bus
Fatory t`.ms otit I:tlso Bus
Fitor)r tims a.it TATA Bus
Package Hierarchy:
e oap.eramql
> B Bagiv
> a) B-java
> a BLrfadotyjaiva
> E owactorygiva
> E| fusojarva
> ff H}usgiva
> EE ttir.jama
a RouRqysjara
E ""jara
Ea VbhickFactnygiva
E@ VEhkk"uerin
ill Vbho.jarva
CCC76
givr uestion 4 (30 marks)
This question is based on the OOP concepts.
You are going to control two types of satellites called Drone -Satellite and Navigational Satellite
from one location called Satellite Center.
a) You can refer to the output given in SatelliteDemo class and adjust your code
accordingly.
public class SatelliteDeno {
public .tatlc void min(String[] args) ill
Isatellite navigationalsatellite = ne-I Havigationsatellite(.Ravana-01-) ;
. IGcolocation lacationTrackerl = ne`g SateuiteLacation{"Sri Lanka-) ;
Isatellite dhonesatellite = lie- Dronesatellite(-Ravana-e2-);
iGcoLacation lacatiinTracker2 s ne- SatelliteLacation(-Russia-);
E=id
rsatellite [ I sateuiteArray = ." Isatellite[]{nevigationelsatellite, dronesatellite};
IGeoLocation [] trackerArray = i" IGeoLceation[]{locationTrackerl, locationTracker2};
Satellitecenter satellitecenter S " Satellitecenter(a, satelliteArray,trackerArray) ;
satellitecenter.startservice();
satellitecenter.stopservice();
Satellitecenter.Iocationservice();
Satellitecenter rerfuecutroller2 a net Sateuitecenter{1, sLatelliteArray,trackerArray) ;
rcoorteGontroller2.startservice();
ref.otecontroller2.stopservlce();
redutecontroller2.Iocatioi.Service
i) Cbnbe s3
ctefmhaeed > Satellbebemo
in nmrigational satellite activate
R8vanm mvigatlonal satellite deacti`ute
Satellite locdtion is = Sri L8nka
`:J Revae®2 dl`one satellite activate
Rar`rane02 drone satellite de®ctivate
Satellite hatioo is = Russia
i). First implement the Isatellite interface and declare activate() and deactivate()
methods. (03 marks)
ii). Then implement the IGeoLocation interface and declare the method called
displayLocation() (02 marks)
iii). Create two classes called I)ronesatellite and Navigationsatellite and implement
the Isatellite interface in each class and override necessary methods in each. You
should overload the constructor to pass the name of the satellite in both classes.
(4 X 2 = 08 marks)
i
CC07B
iv). SimilarlycreateaclasscalledSate]]iteLocationandimplementtheIGeoLocation
interface within the class and override the displayLocation() method. Then
overload the constructor to pass the location of the satellite. (03 marks)
b) The satellite center maintains multiple satellites and multiple Geo Location trackers. To
activate each satellite and the tracker the option can be used as a switch.
i). Create the Satellitecenter class and implement the properties option(int), and
arrayofIsatellite(Isatellite[])andthearrayofIGeoLocation(IGeoLocation[])
tracker.
(02 marks)
ii). Overload the constructor of the same class and initialize the above properties.
(03 marks)
iii). Implement the method called startservice() and you should invoke the activateo
method of the satellite class by using the option as switch. [E.g.: -if opt`i.on = 0 i/
activate Navigation satellite if option = I activate drone satellite] (02 marks)
iv). Implementthemethodcalledstopservice()andyoushouldinvokethedeactivate.()
method.
(02 marks)
v). Then develop the locationservice() method and based on the given option tracker
should invoke the displayLocation() method. (02 marks)
vi). AddanotherDronesatelliteandthetrackerintheSatellitel)emoanddisplayyour
modified output again in the console.
(03 marks)
Save the project as Question04
•E