Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class named Sandwich. Data fields include a String for the main ingredi

ID: 3547783 • Letter: C

Question

Create a class named Sandwich. Data fields include a String for the main ingredients(such as "tuna"), a String for bread type(such as "wheat") and a double for price(such as "4.99"). Include methods to get and set values for each of these fields. Save the class as Sandwich.java.


Part 2


Create an application named TestSandwich that instantiates one Sandwich object and demonstrates the use of the set and get methods. Save this application as TestSandwich.java


I am awarding 750 points if both parts are complete and compile and run correctly. Both most be done in order to get points for this. This is an exercise from Chapter 3 of Joyce Farrell Java Programming only use things that have been learned in the first 3 chapters. Thanks for your help

Explanation / Answer

/////////Sandwich.java.

class Sandwich {
    String main_ingre;
    String bread_type;
    double price;
    public String getMain_ingre() {
        return main_ingre;
    }
    public void setMain_ingre(String main_ingre) {
        this.main_ingre = main_ingre;
    }
    public String getBread_type() {
        return bread_type;
    }
    public void setBread_type(String bread_type) {
        this.bread_type = bread_type;
    }
    public double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }
   
}



////////TestSandwich.java

public class TestSandwich {
    public static void main(String[] args) {
        Sandwich s = new Sandwich();
        s.setBread_type("tuna");
        s.setMain_ingre("wheat");
        s.setPrice(4.99);
       
        System.out.println("Main ingredients of bread is "+s.getMain_ingre());
        System.out.println("Bread type "+s.getBread_type());
        System.out.println("price of bread is "+s.getPrice());

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote