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

*Question after 3 programs import java.awt.Color; import java.awt.Font; import j

ID: 3834379 • Letter: #

Question

*Question after 3 programs

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.text.NumberFormat;

import javax.swing.JOptionPane;

/**
*
*/

/**
* @author
*
*/
public class Instrument {
   public NumberFormat nf = NumberFormat.getCurrencyInstance();
   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 getPicture() {

       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: " + nf.format(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;
      
   }

}

/**
*
*/

/**
* @author
*
*/
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;

   }
}

import java.text.NumberFormat;

import javax.swing.JOptionPane;

/**
*
*/

/**
* @author
*
*/
public class MusicStore {

   /**
   * @param args
   */
   public static void main(String[] args) {
       Instrument [] inventory = new Instrument [6];
   TestMusicStore store = new TestMusicStore();
   store.fillInventory(inventory);
   store.displayMenu(inventory);
       }
   public NumberFormat nf = NumberFormat.getCurrencyInstance();
  
   /**
   * @param inventory
   */
   public void fillInventory (Instrument [] inventory) {
       inventory[0] = new Instrument("Whistle", 62.55, new Picture ("Whistle.PNG"), new Sound ("Whistle.wav"));
   inventory[1] = new Instrument("Harp", 599.99, new Picture ("Harp.PNG"), new Sound ("Harp.wav"));
   inventory[2] = new Percussion("Bongos", 49.99, new Picture ("Bongos.PNG"), new Sound ("Bongos.wav"), "macho", false);
   inventory[3] = new Percussion("Drums", 200.99, new Picture ("drum.jpg"), new Sound ("Drums.wav"), "bass", true);
     
   inventory[4] = new Instrument();
   String tName = JOptionPane.showInputDialog("Please Enter name of an instrument");
   String tcost = JOptionPane.showInputDialog("How much does " + tName + " cost?");
   inventory[4].setName(tName);
   double tCost = 0.0;
   inventory[4].setCost(tCost);
   inventory[4].setPicture(new Picture ("Bell.PNG"));
   inventory[4].setSound(new Sound ("Bell.wav"));
  
   inventory[5] = new Percussion();
   tName = JOptionPane.showInputDialog("Enter Name of a percussion instrument");
   inventory[5].setName(tName);
   tCost = Double.parseDouble(JOptionPane.showInputDialog("How much does " + tName + " cost?"));
   inventory[5].setCost(tCost);
   inventory[5].setPicture(new Picture ("cymbals.jpg"));
   inventory[5].setSound(new Sound ("Cymbals.wav"));
   ((Percussion)inventory[5]).isPitched();
   ((Percussion)inventory[5]).setDrumType("crash");
   }
  
   public void displayMenu(Instrument [] inventory) {
      
       int userSelection = Integer.parseInt(JOptionPane.showInputDialog("Please choose from the following: 1) Select an instrument 2) Display Inventory 3) Listen to Inventory"
+ " 4) Display Total Inventory Values 5) Display Labeled Images 6) Execute final four methods 7 Exit"));
      
   }
}
*Add to MusicStore to do the following:

Call a method named displayMenu with the following choices

1.Select an Instrument

Use a linear search to look for that instrument by name

If the instrument is found display another menu with these choices

Image – displays the object’s image

Sound – plays the object’s sound

Compare Price – finds the first occurrence of this object’s price on Amazon.com using search sequence “suggested retail price”. If found, compare to stored price and determine best deal, else display message.

(http://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Daps&field-keywords= )    use eBay instead

Exit

If the instrument is not found display a message saying so

2.Display Inventory

Use a for-each loop to loop through the array and uses a toString( ) method print to ALL of the information about each object

3.Listen to Inventory

Use a while loop to play all the sounds of the objects in your array (use blockingPlay)

4.Display Total Inventory Value

Compute and display the total cost of all instruments in your array

5.Display Labeled Images

Use a for loop to label (use the method you wrote in your base class) and display all the images of your Instrument objects array. Use 3 different colors and 3 different font sizes.

6.Execute final 4 methods (described below)

7.Exit

Call a method named updateObj2Cost

Display the cost of the second object

Set the cost of the second object in your array to 0

Display the cost of the second object again

Call a method named modifyObj3Image

Negate the picture for the third object in your array and show it

Call a method named modifyObj1Name

Display the name of the first object

Use a predefined method to modify/store the name of the first object to upper case

Display the name of the first object again

Call a method named copyDisplaySubclassObj

Create a new Percussion object and store one of your array objects in it. Display the subclass information only (no base class information) for that object. (hint: typecast)

Explanation / Answer

//Implemantation max up to whatever information is provided

//Please Provide implementation of classes Picture and Sound to Complete this Question.

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.text.NumberFormat;
import javax.swing.JOptionPane;
import java.text.NumberFormat;

//Please provide full implementation
class Picture{
   public Picture(String str) {
      
   }
   public Graphics getGraphics(){
       return null;
   }
}
//Please provide full implementation
class Sound{
   public Sound(String str) {
      
   }
}
public class Instrument {
public NumberFormat nf = NumberFormat.getCurrencyInstance();
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 getPicture() {
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: " + nf.format(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;
  
}
}
/**
*
*/
/**
* @author
*
*/
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;
}
}

public class MusicStore {
/**
* @param args
*/
public static void main(String[] args) {
Instrument [] inventory = new Instrument [6];
MusicStore store = new MusicStore();
store.fillInventory(inventory);
int choice = store.displayMenu(inventory);
switch(choice){
case 1:
   String iName = JOptionPane.showInputDialog("Please Enter name of an instrument");
   break;
case 2:
   System.out.println("==============Inventry=========");
   for(int i=0; i<inventory.length; i++){
       System.out.println(inventory[i].toString());
   }
   break;
case 3:
   System.out.println("==============Instrument Play=========");
   for(int i=0; i<inventory.length; i++){
       System.out.println("Playing......"+inventory[i].getName());
   }
   break;
case 4:
   System.out.println("==============Total inventry=========");
   double total =0;
   for(int i=0; i<inventory.length; i++){
       total += inventory[i].getCost();
   }
   System.out.println("Total :"+total);
   break;
case 5:
   System.out.println("==============Labeled Images=========");
     
   for(int i=0; i<inventory.length; i++){
       System.out.println("Need picture class full implematation ");
   }
   break;
case 7:
   System.exit(0);
}


}
public NumberFormat nf = NumberFormat.getCurrencyInstance();
  
/**
* @param inventory
*/
public void fillInventory (Instrument [] inventory) {
inventory[0] = new Instrument("Whistle", 62.55, new Picture ("Whistle.PNG"), new Sound ("Whistle.wav"));
inventory[1] = new Instrument("Harp", 599.99, new Picture ("Harp.PNG"), new Sound ("Harp.wav"));
inventory[2] = new Percussion("Bongos", 49.99, new Picture ("Bongos.PNG"), new Sound ("Bongos.wav"), "macho", false);
inventory[3] = new Percussion("Drums", 200.99, new Picture ("drum.jpg"), new Sound ("Drums.wav"), "bass", true);

inventory[4] = new Instrument();
String tName = JOptionPane.showInputDialog("Please Enter name of an instrument");
String tcost = JOptionPane.showInputDialog("How much does " + tName + " cost?");
inventory[4].setName(tName);
double tCost = 0.0;
inventory[4].setCost(tCost);
inventory[4].setPicture(new Picture ("Bell.PNG"));
inventory[4].setSound(new Sound ("Bell.wav"));
  
inventory[5] = new Percussion();
tName = JOptionPane.showInputDialog("Enter Name of a percussion instrument");
inventory[5].setName(tName);
tCost = Double.parseDouble(JOptionPane.showInputDialog("How much does " + tName + " cost?"));
inventory[5].setCost(tCost);
inventory[5].setPicture(new Picture ("cymbals.jpg"));
inventory[5].setSound(new Sound ("Cymbals.wav"));
((Percussion)inventory[5]).isPitched();
((Percussion)inventory[5]).setDrumType("crash");
}
  
public int displayMenu(Instrument [] inventory) {
  
int userSelection = Integer.parseInt(JOptionPane.showInputDialog("Please choose from the following: 1) Select an instrument 2) Display Inventory 3) Listen to Inventory"
+ " 4) Display Total Inventory Values 5) Display Labeled Images 6) Execute final four methods 7 Exit"));
return userSelection;
}
}