Question #115943

a) Create a class named Sandwich. Data fields for this class include a String for the main ingredient (E.g. Tuna), a String for bread type (E.g. Wheat) and the third field for double data type to store the sandwich price (N$15.00). Include methods to get and set values for each of these fields. Save the class as Sandwich.java.

Expert's answer

public class Sandwich {
    private String mainIngredient;
    private String breadType;
    private double price;
    
    public String getMainIngredient() {
        return mainIngredient;
    }

    public void setMainIngredient(String mainIngredient) {
        this.mainIngredient = mainIngredient;
    }

    public String getBreadType() {
        return breadType;
    }

    public void setBreadType(String breadType) {
        this.breadType = breadType;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS