CodeHS Java 9.2.6 code example
Example 1: CodeHS java 9.2.7
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 2: CodeHS java 9.2.7
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.";
}
}
Example 3: CodeHS java 9.5.6
import java.util.ArrayList;
public class PieTester
{
public static void main(String[] args)
{
ArrayList<Pie> pies = new ArrayList<Pie>();
Pie applPie = new ApplePie(7);
Pie pumpPie = new PumpkinPie(7, true);
Pie pie = new Pie("blueberry", 7);
pies.add(applPie);
pies.add(pumpPie);
pies.add(pie);
for(int i = 0; i < pies.size(); i++){
System.out.print("Pie: ");
System.out.println(pies.get(i).getType());
}
}
}
Example 4: CodeHS java 9.2.7
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;
}
}