Question: **Question after given code public class Instrument { private String name; private double cost; private String pictureUrl; private String sound; public Instrument() { } /**
**Question after given code
public class Instrument { private String name;
private double cost;
private String pictureUrl;
private String sound;
public Instrument() {
}
/** * * @param name * * @param cost * * @param pictureUrl * * @param sound * */
public Instrument(String name, double cost, String pictureUrl, String sound) {
this.name = name;
this.cost = cost;
if (cost < 0)
cost = 299.99;
this.pictureUrl = pictureUrl;
this.sound = sound;
}
/** * * @return name * */
public String getName() {
return name;
}
/** * * @return cost * */
public double getCost() {
return cost;
}
/** * * @return pictureUrl * */
public String getPictureUrl() {
return pictureUrl;
}
/** * * @return sound * */
public String getSound() {
return sound;
}
/** * * @param name * */
public void setName(String name) {
this.name = name;
}
/** * * @param cost * */
public void setCost(double cost) {
this.cost = cost;
if (cost < 0)
cost = 299.99;
}
/** * * @param pictureUrl * */
public void setPictureUrl(String pictureUrl) {
this.pictureUrl = pictureUrl;
}
/** * * @param sound * */
public void setSound(String sound) {
this.sound = sound;
}
@Override
public String toString() {
return "Name: " + name + ", Cost: " + cost + ", Picture Url: " + pictureUrl + ", Sound: " + sound;
}
public void display(String color, int fontSize) {
System.out.println(name + " Color: " + color + ", Font Size: " + fontSize);
} }
Write the definition for a subclass Percussion for base class Instrument which has the following fields:
1.drumType (e.g. base, snare, tom-tom)
2.pitched (e.g. true or false only)
For the ADT make sure you code the following:
*a no-argument constructor
*another constructor to set all the data of the class
*all accessor and modifier methods
*a toString method
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
