CodeHS java 9.2.7 code example

Example 1: CodeHS java 9.2.7

//CodeHS AP Computer Science A Java, 9.2.7: Instruments
//DO NOT COPY AND PASTE, YOUR TEACHER CAN SEE YOUR EDIT HISTORY.
//Part 1/3
//Wind.java 

public class Wind extends Instrument
{
    boolean reed;
    
    public Wind(String name, String family, boolean reed){
        super(name, family);
        this.reed = reed;
    }
    
    public boolean getReed(){
        return reed;
    }
    
    public void setReed(boolean bool){
        this.reed = bool;
    }
 
}

Example 2: CodeHS java 9.2.7

//CodeHS AP Computer Science A Java, 9.2.7: Instruments
//DO NOT COPY AND PASTE, YOUR TEACHER CAN SEE YOUR EDIT HISTORY.
//Part 3/3
//Strings.java

public class Strings extends Instrument
{
    
    public Strings(String name, String family, boolean bow){
        super(name, family);
        this.bow = bow;
    }
    
    public Strings(String name, boolean bow){
        super(name, "Strings");
        this.bow = bow;
    }
    
    boolean bow;
       
    public boolean getBow(){
        return this.bow;
    }
    
    public void setBow(boolean bool){
        this.bow = bool;
    }
}

Example 3: CodeHS java 9.2.7

//CodeHS AP Computer Science A Java, 9.2.7: Instruments
//DO NOT COPY AND PASTE, YOUR TEACHER CAN SEE YOUR EDIT HISTORY.
//Part 2/3
//Instrument.java

public class Instrument
{
    String name = "";
    String family = "";
    
    public Instrument(String name, String family){
        this.name = name;
        this.family = family;
    }
    
    public Instrument(String name){
        this.name = name;
    }
    
    public void setName(String str){
        this.name = str;
    }
    
    public String getName(){
        return this.name;
    }
    
    public void setFamily(String str){
        this.family = str;
    }
    
    public String getFamily(){
        return this.family;
    }
    
    public String toString(){
        return name + " is a member of the " + family + " family.";
    }
    
}

Tags:

Java Example