Create an application named TestSandwich_[your name] that instantiates one Sandwich object and demonstrates the use of the set and get methods.
import java.util.ArrayList;
public class Sandwich {
private String bread;
private ArrayList<String> filling = new ArrayList<>();
private double price;
public void setBread(String typeOfBread){
this.bread = typeOfBread;
}
public void setFilling(String ingredient){
this.filling.add(ingredient);
}
public void setPrice(double amountOfMoney){
this.price = amountOfMoney;
}
public String getBread(){
return bread;
}
public ArrayList<String> getFilling(){
return filling;
}
public Double getPrice(){
return price;
}
}
public class Test {
public static void main(String args[]){
Sandwich sandwichStandart = new Sandwich();
sandwichStandart.setBread("wheat");
sandwichStandart.setFilling("lettuce");
sandwichStandart.setFilling("ham");
sandwichStandart.setFilling("cheese");
sandwichStandart.setFilling("tomato");
sandwichStandart.setPrice(2.75);
System.out.println("Bread: " + sandwichStandart.getBread());
System.out.println("Filling: " + sandwichStandart.getFilling());
System.out.println("Price: " + sandwichStandart.getPrice());
}
}
Comments
Leave a comment