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

Create a class for the Tip Top Bakery named Bread with private data fields for b

ID: 3707773 • Letter: C

Question

Create a class for the Tip Top Bakery named Bread with private data fields for bread type (such as “rye”) and calories per slice. Include a constructor that takes parameters for each field, and include get methods that return the values of the fields. Include toString and equals methods.

Write an application named TestBread to instantiate three Bread objects with different values, and then display all the data for each object. OR

RECOMMENDED: Create JUnit tests BreadTest.java that tests all of the methods in Bread.

Create a class named SandwichFilling. Include a field for the filling type (such as “egg salad”) and another for the calories in a serving. Include a constructor that takes parameters for each field, and include get methods that return the values of the fields. Include toString and equals methods.

Write an application named TestSandwichFilling to instantiate three SandwichFilling objects with different values, and then display all the data for each object. OR

RECOMMENDED: Create JUnit tests SandwichFillingTest.java that tests all of the methods in SandwichFilling.

Create a class named Sandwich. Include a private Bread field and a private SandwichFilling field. Include a constructor that takes parameters for each field needed in the two objects and assigns them to each object’s constructor. Write totalCalories method, which assumes that each Sandwich is made using two slices of Bread. Include toString and equals methods.

Write an application named TestSandwich to instantiate three Sandwich objects with different values, and then display all the data for each object, including the total calories in a Sandwich, assuming that each Sandwich is made using two slices of Bread. OR

RECOMMENDED: Create JUnit tests SandwichTest.java that tests all of the methods in Sandwich.

Explanation / Answer

CODE:

public class Sandwich {

   Bread bread;

   SandwichFilling sandwich;

   Sandwich(String type,float calories, String filling,float cal) {

       bread =new Bread(type,calories);

       sandwich =new SandwichFilling(filling,cal);

   }

   public Bread getBread() {

       return bread;

   }

   public void setBread(Bread bread) {

       this.bread = bread;

   }

   public SandwichFilling getSandwich() {

       return sandwich;

   }

   public void setSandwich(SandwichFilling sandwich) {

       this.sandwich = sandwich;

   }

}

TestSandwich.java:

public class TestSandwich {

   public static void main(String args[]) {

       Sandwich s1 = new Sandwich("bread1", 200, "egg salad", 300);

       Sandwich s2 = new Sandwich("bread2", 200, "filling1", 500);

       Sandwich s3 = new Sandwich("bread3", 200, "filling2", 400);

       System.out.println("Sandwich 1:");

       System.out.println("Bread Type :"+s1.bread.getType());

       System.out.println("Filling Type :"+s1.sandwich.getFillingType());

       System.out.println("Total calories: " + 2 * s1.bread.getCalories());

       System.out.println();

       System.out.println("Sandwich 2:");

       System.out.println("Bread Type :"+s2.bread.getType());

       System.out.println("Filling Type :"+s2.sandwich.getFillingType());

       System.out.println("Total calories: " + 2 * s2.bread.getCalories());

       System.out.println();

     

       System.out.println("Sandwich 3:");

       System.out.println("Bread Type :"+s3.bread.getType());

       System.out.println("Filling Type :"+s3.sandwich.getFillingType());

       System.out.println("Total calories: " + 2 * s3.bread.getCalories());

       System.out.println();

   }

}

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