Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the definition for a base class Instrument which has the following fields/

ID: 3827728 • Letter: W

Question

Write the definition for a base class Instrument which has the following fields/methods:

1.name (e.g. “Tuba”)

2.cost (e.g. “$567.89”)

3. a picture of the instrument

4. a sample of the sound the instrument makes

*Include logic to verify that the cost is greater than zero. If it isn’t, display a message in a dialog box and set the cost to a default value of 299.99

*Code a method that will display the name of the instrument on its image in the color and font size passed into the method as parameters

For each 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
*Include Javadoc comments/tags for each class and all methods

Explanation / Answer

Hi, Please find my implementation.

You have asked for ADT.

I have not implemented GUI part.

/**

* @author pravesh

*

*/

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);

   }

}