Lab Work 2 UML Practice and Open Closed Principle Goal: Remembering Class Diagrams and Demonstration of OCP through an example
UML Practice In this part of the lab, your task is to implement the code for the class diagram given below.
Oicnesue
C rdet
ams
Stnd
Instumenie Arta Lisi
nndemnanimaciacunt
FaYoid adnnannerkIneinuten *Jud
Fourd Void
Ataa
Snros
Rejond:
Please don't forget to add get/set methods and proper constructors for the classes. They are omitted for simplicity: noOflnstruments: Number of instrument instances sound(): prints out the sound of the instrument or You may just print the name of the instrument: play(): calls sound() method of each instrument in order.
2. In your main, please instantiate 2 different instruments from each subtype and add them to the Orchestra: Print the noOflnstruments and then call play()_
Note: Save_the_finished version ofyour codeYou willuse_itin the next week
Demonstration of OCP We have discussed Open Closed Principle using' computer parts example in the lecture: However; we have only analyzed code excerpts, not the whole program In this lab you will be asked to give full implementation demonstrating the OCP_ You are going to provide the following classes: PricePolicy Part Motherboard Memory HardDisk You are also going to write a function called totalPrice Write a main to test your program Create an array of parts which makes up a computer Calculate the price of the computer Demonstrate the Open-Closed Principle by extending the software using new part called OpticalDisk creating a new price policy and update HardDisk and Memory objects using new price policies: In your program list classes/modules/functions that do not change even though the parts get different prices by adding comment to the source file