Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2 . 8 LAB: Instrument information ( derived classes ) Given the base class Instrument, define a derived class StringInstrument for string instruments with a

2.8 LAB: Instrument information (derived classes)
Given the base class Instrument, define a derived class StringInstrument for string instruments with a constructor that initializes the attributes of the Instrument class as well as new attributes of the following types
integer to store the number of strings
integer to store the number of frets
boolean to store whether the instrument is bowed
Ex. If the input is:
Drums
Zildjian
2015
2500
Guitar
Gibson
2002
1200
6
19
False 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(f'Instrument Information:')
print(f' Name: { self.name }')
print(f' Manufacturer: { self.manufacturer }')
print(f' Year built: { self.year_built }')
print(f' Cost: { self.cost }')
class StringInstrument(Instrument):
public class StringInstrument extends Instrument {
private int numberOfStrings;
private int numberOfFrets;
private boolean isBowed;
public StringInstrument(String name, String sound, int numberOfStrings, int numberOfFrets, boolean isBowed){
super(name, sound);
this.numberOfStrings = numberOfStrings;
this.numberOfFrets = numberOfFrets;
this.isBowed = isBowed;
}
}
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())
is_bowed = input()== 'True'
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, is_bowed)
my_instrument.print_info()
my_string_instrument.print_info()
print(f' Number of strings: { my_string_instrument.num_strings}')
print(f' Number of frets: { my_string_instrument.num_frets}')
print(f' Is bowed: { my_string_instrument.is_bowed}')

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

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

=+c) In what month of the year are gas prices highest?

Answered: 1 week ago

Question

I wasnt sure how to talk about this situation. It was too personal.

Answered: 1 week ago