Answered step by step
Verified Expert Solution
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
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
Guitar
Gibson
False class Instrument:
def initself name, manufacturer, yearbuilt, cost:
self.name name
self.manufacturer manufacturer
self.yearbuilt yearbuilt
self.cost cost
def printinfoself:
printfInstrument Information:
printf Name: self.name
printf Manufacturer: self.manufacturer
printf Year built: self.yearbuilt
printf Cost: self.cost
class StringInstrumentInstrument:
public class StringInstrument extends Instrument
private int numberOfStrings;
private int numberOfFrets;
private boolean isBowed;
public StringInstrumentString name, String sound, int numberOfStrings, int numberOfFrets, boolean isBowed
supername sound;
this.numberOfStrings numberOfStrings;
this.numberOfFrets numberOfFrets;
this.isBowed isBowed;
if namemain:
instrumentname input
manufacturername input
yearbuilt intinput
cost intinput
stringinstrumentname input
stringmanufacturer input
stringyearbuilt intinput
stringcost intinput
numstrings intinput
numfrets intinput
isbowed input 'True'
myinstrument Instrumentinstrumentname, manufacturername, yearbuilt, cost
mystringinstrument StringInstrumentstringinstrumentname, stringmanufacturer, stringyearbuilt, stringcost numstrings, numfrets, isbowed
myinstrument.printinfo
mystringinstrument.printinfo
printf Number of strings: mystringinstrument.numstrings
printf Number of frets: mystringinstrument.numfrets
printf Is bowed: mystringinstrument.isbowed
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started