193k views
3 votes
Given main() and the Instrument class, 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

User Per Huss
by
3.4k points

1 Answer

4 votes

Answer:

Step-by-step explanation:

The following derived class called StringInstrument extends the Instrument class and creates the necessary private variables for number of Strings and number of Frets. Then it creates getter and setter methods for each of the variables. This allows them to be called within the main method that has already been created and output the exact sample output as seen in the question.

class StringInstrument extends Instrument {

private int numStrings, numFrets;

public int getNumOfStrings() {

return numStrings;

}

public void setNumOfStrings(int numStrings) {

this.numStrings = numStrings;

}

public int getNumOfFrets() {

return numFrets;

}

public void setNumOfFrets(int numFrets) {

this.numFrets = numFrets;

}

}

Given main() and the Instrument class, define a derived class, StringInstrument, for-example-1
User PluckyDuck
by
3.4k points