In this exercise, you are going to build a hierarchy to create instrument objects. We are going to create part of the orchestra using three classes, Instrument, Wind, and Strings. Note that the Strings class has a name very close to the String class, so be careful with your naming convention! We need to save the following characteristics: Name and family should be saved for all instruments We need to specify whether a strings instrument uses a bow We need to specify whether a wind instrument uses a reed Build the classes out with getters and setters for all classes. Only the superclass needs a toString and the toString should print like this: Violin is a member of the Strings family. Your constructors should be set up to match the objects created in the InstrumentTester class.
These are the files given
public class InstrumentTester
{
public static void main(String[] args)
{
/**
* Don't Change This Tester Class!
*
* When you are finished, this should run without error.
*/
Wind tuba = new Wind("Tuba", "Brass", false);
Wind clarinet = new Wind("Clarinet", "Woodwind", true);
Strings violin = new Strings("Violin", true);
Strings harp = new Strings("Harp", false);
System.out.println(tuba);
System.out.println(clarinet);
System.out.println(violin);
System.out.println(harp);
}
}
////////////////////////////
public class Wind extends Instrument
{
}
///////////////////////////
public class Strings extends Instrument
{
}
/////////////////////////
public class Instrument
{
}

Respuesta :

Answer:

Explanation:

The following code is written in Java and creates all of the necessary classes as requested so that the main class runs perfectly without having to change anything...

package sample;

class InstrumentTester {

   public static void main(String[] args) {

       /*** Don't Change This Tester Class!** When you are finished, this should run without error.*/

       Wind tuba = new Wind("Tuba", "Brass", false);

       Wind clarinet = new Wind("Clarinet", "Woodwind", true);

       Strings violin = new Strings("Violin", true);

       Strings harp = new Strings("Harp", false);

       System.out.println(tuba);

       System.out.println(clarinet);

       System.out.println(violin);

       System.out.println(harp);

   }

}

class Wind extends Instrument {

   boolean usesReef;

   public Wind(String name, String family, boolean usesReef) {

       this.setName(name);

       this.setFamily(family);

       this.usesReef = usesReef;

   }

   public boolean isUsesReef() {

       return usesReef;

   }

   public void setUsesReef(boolean usesReef) {

       this.usesReef = usesReef;

   }

}

class Strings extends Instrument{

   boolean usesBow;

   public Strings (String name, String family, boolean usesBow) {

       this.setName(name);

       this.setFamily(family);

       this.usesBow = usesBow;

   }

   public Strings (String name, boolean usesBow) {

       this.setName(name);

       this.setFamily("String");

       this.usesBow = usesBow;

   }

   public boolean isUsesBow() {

       return usesBow;

   }

   public void setUsesBow(boolean usesBow) {

       this.usesBow = usesBow;

   }    

}

class Instrument{

   private String family;

   private String name;

   public String getName() {

       return name;

   }

   public void setName(String name) {

       this.name = name;

   }

   public String getFamily() {

       return family;

   }

   public void setFamily(String family) {

       this.family = family;

   }

   public String toString () {

       System.out.println(this.getName() + " is a member of the " + this.getFamily() + " family.");

       return null;

   }

}