Given the base class Instrument, define a derived class StringInstrument for string instruments. Ex: If the input is: Drums Zildjian 2015 2500 Guitar Gibson 2002

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question

Given the base class Instrument, define a derived class StringInstrument for string instruments.

Ex: If the input is:

Drums

Zildjian

2015

2500

Guitar

Gibson

2002

1200

6

19

the output is:

Instrument Information:

       Name: Drums

       Manufacturer: Zildjian

       Year built: 2015

       Cost: 2500

Instrument Information:

       Name: Guitar

       Manufacturer: Gibson

       Year built: 2002

       Cost: 1200

       Number of strings: 6

       Number of frets: 19

 

 

code to be used:

class Instrument:
    def __init__(self, name, manufacturer, year_built, cost):
        self.name = name
        self.manufacturer = manufacturer
        self.year_built = year_built
        self.cost = cost
      
    def print_info(self):
        print('Instrument Information:')
        print('   Name:', self.name)
        print('   Manufacturer:', self.manufacturer)
        print('   Year built:', self.year_built)
        print('   Cost:', self.cost)


class StringInstrument(Instrument):
    # TODO: Define constructor with attributes: 
    #       name, manufacturer, year_built, cost, num_strings, num_frets
      

if __name__ == "__main__":
    instrument_name = input()
    manufacturer_name = input()
    year_built = int(input())
    cost = int(input())
    string_instrument_name = input()
    string_manufacturer = input()
    string_year_built = int(input())
    string_cost = int(input())
    num_strings = int(input())
    num_frets = int(input())
    
    my_instrument = Instrument(instrument_name, manufacturer_name, year_built, cost)
    my_string_instrument = StringInstrument(string_instrument_name, string_manufacturer, string_year_built, string_cost, num_strings, num_frets)

    my_instrument.print_info()
    my_string_instrument.print_info()
   
    print('   Number of strings:', my_string_instrument.num_strings)
    print('   Number of frets:', my_string_instrument.num_frets)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr