*Question after base and derived class public class Instrument { private String
ID: 3831563 • Letter: #
Question
*Question after base and derived class
public class Instrument {
private String name;
private double cost;
private Picture picture;
private Sound sound;
/**
* no argument constructor
*/
public Instrument() {
}
/**
*
* @param name
*
* @param cost
*
* @param picture
*
* @param sound
*
*/
public Instrument(String name, double cost, Picture picture, Sound sound) {
this.name = name;
this.cost = cost;
this.picture = picture;
this.sound = sound;
}
/**
*
* @return name
*
*/
public String getName() {
return name;
}
/**
*
* @return cost
*
*/
public double getCost() {
return cost;
}
/**
*
* @return picture
*
*/
public Picture getPictureUrl() {
return picture;
}
/**
*
* @return sound
*
*/
public Sound 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;
JOptionPane.showMessageDialog(null, "Cost is less than zero, default cost set to $299.99");
}
/**
*
* @param picture
*
*/
public void setPicture(Picture picture) {
this.picture = picture;
}
/**
*
* @param sound
*
*/
public void setSound(Sound sound) {
this.sound = sound;
}
@Override
public String toString() {
return "Name: " + name + ", Cost: " + cost + ", Picture Url: " + picture + ", Sound: " + sound;
}
public Picture labelImage(Color c, int fontSize)
{
Picture temp = picture;
Graphics g = temp.getGraphics();
g.setColor(c);
g.setFont(new Font("Arial",Font.BOLD,fontSize));
g.drawString(name, 25, 75);
return temp;
}
}
public class Percussion extends Instrument {
private String drumType;
private boolean pitched;
/**
*no argument constructor
*/
public Percussion() {
}
/**
* @param name
*
* @param cost
*
* @param pictureUrl
*
* @param sound
*
* @param drumType
*
* @param pitched
*
*/
public Percussion(String name, double cost, Picture picture,
Sound sound, String drumType, boolean pitched) {
super(name, cost, picture, sound);
this.drumType = drumType;
this.pitched = pitched;
}
/**
*
* @return drumType
*
*/
public String getDrumType() {
return drumType;
}
/**
*
* @return pitched
*
*/
public boolean isPitched() {
return pitched;
}
/**
*
* @param drumType
*
*/
public void setDrumType(String drumType) {
this.drumType = drumType;
}
/**
*
* @param pitched
*
*/
public void setPitched(boolean pitched) {
this.pitched = pitched;
}
@Override
public String toString() {
return super.toString() + ", Drum Type" + drumType + ", Is pitched: " + pitched;
}
}
To test your new class do the following:
*Create a class MusicStore that contains a ‘main’ method with the following functionality:
*Create one array that will hold 3 Instrument objects and 3 Percussion objects
*Call a method named fillInventory which does the following
Instantiate 4 array objects (2 of each type) using the constructor with parameters
Instantiate one of each type of object using the no parameter constructor
Use input dialog boxes to input the name and the cost for the 2 ‘default’ objects, and then use set methods to store data for each default object
*Include javadoc and comments
Explanation / Answer
Note :please provide Picture and Sound classes for completing the solution
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.