Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design and implement the interface and class hierarchy shown in Figure 1 to demonstrate the relationships and functions among various musical instruments in a typical

Design and implement the interface and class hierarchy shown in Figure 1 to demonstrate the relationships and functions among various musical instruments in a typical musical instrument store. As shown in the figure, Repairable, PriceProvider, and Playable are interfaces, each containing a single abstract method how_to_repair(), get_price() and how_to_play(), respectively. The dotted line from a class to an interface indicates the interface class inheritance (e.g., StringFamily, PercussionFamily classes implement Repairable and Playable interfaces meaning either these classes or their subclasses must implement the abstract methods in those interfaces. Similarly, WoodwindFamily class implements only Playable interface, not the Repairable interface, FAST, Sheridan College Assignment 1 Page 2 of 7 assuming instruments in this category can not be repaired. Also, only class MusicalInstrument or its subclasses implement PriceProvider interface.) The class MusicalInstrument is an abstract class containing an abstract method make_sound(), which must be implemented (overridden) by its concreted subclasses (i.e., Violin, Harp, Piano, Drum, Xylophone and Flute). Most information handled and/or returned by interface and abstract class methods are presented in Table 1. In addition to that, some class may contain their specific attributes, which are discussed below. Use this table along with the description below for information to be returned/handled by the method(s) within respective classes. Table 1: Information about musical instruments Instrument Make sound Price How to play How to repair Drum Vibrating stretched membrane $349.50 By hitting the membrane with sticks Replace the membrane Flute Guiding a stream of air $74.99 By blowing into the flute <> Repairable how_to_repair(): str make_sound (): str MusicalInstrument <> Playable how_to_play(): str <> PriceProvider get_price(): str Harp StringFamily Violin Flute WoodwindFamilyPercussionFamily Drum XylophonePiano Figure 1: UML diagram showing class interface relationship of musical instruments. FAST, Sheridan College Assignment 1 Page 3 of 7 Harp Vibrating strings $255.00 By strumming the strings and peddling to adjust the string lengths Replace the broken strings Piano Vibrating the soundboard $725.00 By hitting the keys that trigger hammers to hit the strings Replace the broken strings or keys Violin Vibrating strings $350.00 By resting the violin on shoulder, plucking the strings bow and picking notes with fingers Replace the broken bridge Xylophone Through resonators $49.00 By hitting bars with two mallets Replace the broken keys Details about the classes and interfaces are below: Class StringFamily [10 marks]: All StringFamily instruments e.g., Harp, Violin and Piano should have a number of strings. Use appropriate attribute inheritance to deal with this attribute between this superclass and its subclasses. Class PercussionFamily [10 marks]: Assume all PerecussionFamily instruments e.g., Xylophone, Drum and Piano should have a number of keys. Use appropriate attribute inheritance to deal with this attribute between this superclass and its subclasses. In addition to the inherited attributes, class Drum should also have an attribute called diameter_in_inch indicating the diameter of the drum surface in inch. Note: As shown in the figure, class Piano inherits both StringFamily and PercussionFamily since pianos have both strings and keys. Class WoodwindFamily [10 marks]: Every WoodwindFamily instrument has an attribute called made of which will return made of wood, assuming all instrument in this family are made of wood. Also, instruments in this family, e.g., Flute, can not be fixed when broken or damaged, hence this class or its subclasses do not implement Repairable interface. Class Order [7 marks] In addition to the classes shown in the UML in Figure 1, develop another class called Order to keep track of orders for musical instruments by different customers. Along with required accessors and mutators, the Order class should have following attributes at a minimum: o_id: an id of the order. customer_name: the name of the customer making the order. orders: a list of musical instruments ordered by the customer. add_instrument(self, instrument): an instance method to be used to add an instrument (passed by the argument) to the orders list. FAST, Sheridan College Assignment 1 Page 4 of 7 Testing the implementation [8 marks]: Create a tester class called Tester_ to test your implementation. In your tester class, create at least one object of each instrument as below: drum = Drum(0, 20) # this drum has 0 keys and the size of its diameter is 20. (Assume drum does not have any key.) flute = Flute() # this flute does not have any specific attribute, except the inherited ones. harp = Harp(40) # this harp has 40 strings piano = Piano(88, 230) # this piano has 88 keys and 230 strings violin = Violin(4) # this violin has 4 strings xylophone = Xylophone(25) # this xylophone has 25 keys and provide the following outputs. [Do not hard code any data for any output, it should be obtained through invoking the respective method.] Outputs 1 6 [20 marks]: Programmatically display the sound making, play method, repair method and the price for each instrument (except no repair method for flute) as shown in Outputs 1 to 6 below. FAST, Sheridan College Assignment 1 Page 5 of 7 Output 7 [10 marks]: Create a list of instruments and add all the above instruments in it. Then for each instrument in the list, display only its special feature (e.g., number of keys for percussion family instruments, number of strings for string family instruments, diameter of a drum, and made of for woodwind family instruments.). See the output below. Again, do not hard code any output data, you must obtain the values programmatically through invoking appropriate method offered in the class. Output 8 [10 marks]: Use lists sort() method to sort the instruments in the instrument list in price ascending order. [Hint: you may need to implement __ge__() and __lt__() magic methods in an appropriate class to facilitate the sorting on the instrument list.] Display the name of the instrument and its price by walking through the sorted instrument list, as below. Output 9 [15 marks]: Create following two orders by two customers Bob and Alice, respectively: order_Bob = Order(111, Bob) # id of the order = 111 and customer name = Bob order_Alice = Order(222, Alice) # id of the order = 222 and customer name = Alice FAST, Sheridan College Assignment 1 Page 6 of 7 Have order_Bob order for one of each percussion family instrument and order_Alice order for one of each string family instrument. [Hint: Walkthrough the instrument list and add percussion family instruments in the orders list of order_Bob, and string family instruments in the orders list of order_Alice. Make use of the add_instrument(self, instrument) method.] Once the order list of Bob and Alice is populated, output the total price of all the instruments in each list, see the output below. Create another order instance for a custom order where the order id should be the last 3 digits of your Sheridan student number and use your first name as the customers name. Then, ask the user to enter a set of instruments that you want to order. Please see the output below as a guide to obtain user input for instrument choices. For example, in the output below, user ordered for a flute, a drum, a xylophone and a piano by typing the string fdxp. The program then extracted each letter from the input string to learn about the instruments ordered and create the order list. This is a guideline only, you can use your own way to obtain user choice for instruments. Once the order list is created, output the total price of all the instruments ordered along with the names of instruments ordered (see the output below). Important requirements: Demonstrate industry standard design e.g., applying generalization or specialization of attributes when possible.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started