Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python program Musical Instruments Design and implement the interface and class hierarchy shown in Figure 1 to demonstrate the relationships and functions among various musical

python program
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Musical Instruments 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 ho_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, Figure 1: UML diagram showing class interface relationship of musical instruments. assuming instruments in this category can not be repaired. Also, only class Musicallnstrument 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, Horp, Piano, Drum, Xylophone and Flute). The class Musicallinstrument 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 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 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. Page 3 of 7 FAST, Sheridan College Assignment 1 Testing the implementation [8 marks]: Create a tester class called Tester > to test vour implementation. In vour tester class. create at least one obiect of each instrument as Testing the implementation [ 8 marks]: Create a tester class called Tester_ Your First Name 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. Outputs 16 [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. Details of Violin Wakes sound: vibrating the string Play method: resting the violin on shoulder, plucking the strings bow and picking notes with fingers Repair method: replace the broken bridge The price: 350.0 Details of Xylophone Makes sound: through resonators Play method: hitting barss with two mallets Repair method: replace the broken keys The price: 89.99 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. SPECTAL FEATURES Key count of Xylophone is: 25 Key count of Drun is: The diaseter of Drua is: 20 inch string count of Harp is: 40 string count of Plano is: 88 Key count of Piano is: 230 Fluet is: Made of nood string count of violin is: 4 Output 8 [10 marks]: Use list's sorti) method to sort the instruments in the instrument list in price ascending order. [Hint: you may need to implement_ge () and _ It (l) magic methods in an appropriate class to facilitate the sorting on the instrument list.] Display the name of the Output 8 [10 marks]: Use list's sort() method to sort the instruments in the instrument list in price ascending order. [Hint: you may need to implement__ge () and____ () 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. Create following two orders by two customers Bob and Alice, respectively: order_ Bob =Order(111, O Bob' )# id of the order =111 and customer name =B0b order_Alice =Order(222, 'Alice' ) H id of the order =222 and customer name = Alice Have order_Bob order for one of each percussion family instrument and order_Alice ord or one of each string family instrument. [Hint: Walkthrough the instrument list and ad percussion family instruments in the orders list of order_Bob, and string famil 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 customer's 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). Please enter your order by typing the letter for each instrument without any space d= Drum, f= Fluet,h= Harp, p= Piano, v= Violin, and X=X Xlophone hdv Syed ordered for ['Drum', 'Harp', 'Violin'] Order total for Syed (999): 955.49 Important requirements: - Demonstrate industry standard design e.g., applying generalization or specialization of attributes when possible. - All interfaces should be placed in a separate module named: interfaces_cyour First Name>. - The Musicalinstrument class should be implemented in a separate module named Instruments_. - Classes PercussionFamily, Drum and Xylophone should be implemented in a separate module named PercussionFamily_. - Class Piano should be implemented in a separate module named Piano_. - Class Order should be implemented in a separate module named OrderList_. - Use a separate class called Tester_

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

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions