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

This is lab7(burrito class) https://www.chegg.com/homework-help/questions-and-an

ID: 3712207 • Letter: T

Question

This is lab7(burrito class)

https://www.chegg.com/homework-help/questions-and-answers/objectives-1-using-java-compiler-rte-creating-java-application-2-designing-creating-using--q28398656

PF1 Lab8 A Bigger, Better Burrito!

OBJECTIVE: Demonstrating the OO concept of inheritance by creating a subclass of an existing class. Place your file (Lab8.java) in ~/PF1/lab8 PROCEDURE: Assume that our original Burrito object required lots and lots of work to design and create. We now want to create a similar object with a few additional ingredients. Instead of starting from scratch, let's leverage off of our existing work and create a derived class (subclass) of our Burrito. The subclass will be called BurritoSupreme. It will have the same ingredients as a regular Burrito, plus add sour cream and black olives. NOTE: DO NOT ALTER YOUR BURRITO CLASS. You should be able to create the BurritoSupreme objects while leaving the original Burrito class UNTOUCHED. DO NOT DUPLICATE CODE FROM THE BURRITO CLASS, instead, INHERIT the code and build upon it! (you should, however, copy the Burrito.class file from your lab7 to your lab8 directory) Furthermore, do NOT try to access/modify beef, beans, cheese or salsa from your BurritoSupreme class!!! Your program needs to construct two BurritoSupremes. One is a "default" burrito (supreme) which consists of the same ingredients as the default regular burrito, plus one unit of sour cream and olives each. The second burrito (supreme) will be created based on the values which are entered interactively as your program runs. You will prompt the user for their name and the amount of each ingredient and then create a BurritoSupreme to those specs. Your main method should prompt the user and read in the desired quantities of beef, beans, cheese, salsa, sour cream and black olives and pass those values, plus the customer name to the BurritoSupreme constructor! Like the previous lab, your program should, for each burrito, invoke the print_order() and weight methods to print out the specs of the burrito before and after invoking gutBuster(). Note: The gutBuster() method needs to double the amount of ALL ingredients. Following are a few lines of code from my program:

==========================================================================

BurritoSupreme b0 = new BurritoSupreme(); b0.print_order(); System.out.println("The burrito weighs " + b0.weight() + " ounces"); b0.gutBuster(); b0.print_order(); System.out.println("The burrito weighs " + b0.weight() + " ounces");

== OUTPUT ================================================================

Making a default BurritoSupreme No Name's burrito will be made of: 2 ounce(s) of beans 1 ounce(s) of beef 1 ounce(s) of cheese 1 ounce(s) of salsa 1 ounce(s) of sour cream 1 ounce(s) of black olives The burrito weighs 7 ounces. Invoking the Gut Buster Special!!! Invoking the Gut Buster Special!!! No Name's burrito will be made of: 4 ounce(s) of beans 2 ounce(s) of beef 2 ounce(s) of cheese 2 ounce(s) of salsa 2 ounce(s) of sour cream 2 ounce(s) of black olives The burrito weighs 14 ounces. ==========================================================================

Explanation / Answer

Hello, the required code is attached below. I have answered the question for creating Burrito class, so I have created BurritoSupreme class extended from Burrito class and implemented all the required methods. Also defined a Test class with a main method to demonstrate the working. Thanks.

// Burrito.java

public class Burrito {

                // attributes specifying units of each ingredients

                private int beans;

                private int beef;

                private int cheese;

                private int salsa;

                private String customerName;

                /**

                * Default constructor

                */

                public Burrito() {

                                /**

                                * Default values

                                */

                                beans = 2;

                                beef = 1;

                                cheese = 1;

                                salsa = 1;

                                customerName = "No Name";

                }

                /**

                * constructor to initialize all fields

                */

                public Burrito(int beans, int beef, int cheese, int salsa,

                                                String customerName) {

                                /**

                                * Initializing all fields

                                */

                                this.beans = beans;

                                this.beef = beef;

                                this.cheese = cheese;

                                this.salsa = salsa;

                                this.customerName = customerName;

                }

                /**

                * method to display the contents of the Burrito

                */

                public void print_order() {

                                System.out.println(customerName + "'s burrito will be made of:");

                                System.out.println(beans + " ounce(s) of beans");

                                System.out.println(beef + " ounce(s) of beef");

                                System.out.println(cheese + " ounce(s) of cheese");

                                System.out.println(salsa + " ounce(s) of salsa");

                }

                /**

                * method to return the weight of the burrito

                * @return - sum total of all units of ingredients

                */

                public int weight() {

                                return beans + beef + salsa + cheese;

                }

                /**

                * special method to double all ingredients

                */

                public void gutBuster() {

                                beans = 2 * beans;

                                beef = 2 * beef;

                                cheese = 2 * cheese;

                                salsa = 2 * salsa;

                                System.out.println("Invoking the Gut Buster Special!!!");

                }

               

}

// BurritoSupreme.java

public class BurritoSupreme extends Burrito {

                // additional attributes

                private int sour_cream;

                private int black_olives;

                /**

                * Default constructor

                */

                public BurritoSupreme() {

                                super();

                                sour_cream = 1;

                                black_olives = 1;

                }

                /**

                * constructor to initialize all fields

                */

                public BurritoSupreme(int beans, int beef, int cheese, int salsa,

                                                String customerName, int sour_cream, int black_olives) {

                                /**

                                * passing required values to super class constructor

                                */

                                super(beans, beef, cheese, salsa, customerName);

                                this.sour_cream = sour_cream;

                                this.black_olives = black_olives;

                }

                /**

                * overriding print order method to print details of extra attributes

                */

                @Override

                public void print_order() {

                                super.print_order();

                                System.out.println(sour_cream + " ounce(s) of sour cream");

                                System.out.println(black_olives + " ounce(s) of black olives");

                }

                /**

                * overriding weight method to include details of extra attributes

                */

                @Override

                public int weight() {

                                /**

                                * adding additional attributes to the value returned by super class

                                * method

                                */

                                return super.weight() + sour_cream + black_olives;

                }

                /**

                * overriding gut buster method to include doubling of extra attributes

                */

                @Override

                public void gutBuster() {

                                /**

                                * doubling super class attributes

                                */

                                super.gutBuster();

                                /**

                                * doubling extra attributes

                                */

                                sour_cream = 2 * sour_cream;

                                black_olives = 2 * black_olives;

                }

}

//Test.java

import java.util.Scanner;

public class Test {

                public static void main(String[] args) {

                                /**

                                * Creating a burrito supreme using default constructor

                                */

                                BurritoSupreme b0 = new BurritoSupreme();

                                b0.print_order();

                                System.out.println("The burrito weighs " + b0.weight() + " ounces");

                                b0.gutBuster();

                                b0.print_order();

                                System.out.println("The burrito weighs " + b0.weight() + " ounces");

                                /**

                                * gathering user input for another burrito supreme

                                */

                                Scanner scanner = new Scanner(System.in);

                                System.out.println(" Creating a Burrito supreme from user input ");

                                System.out.print("Enter quantity for beans: ");

                                int beans = scanner.nextInt();

                                System.out.print("Enter quantity for beef: ");

                                int beef = scanner.nextInt();

                                System.out.print("Enter quantity for cheese: ");

                                int cheese = scanner.nextInt();

                                System.out.print("Enter quantity for salsa: ");

                                int salsa = scanner.nextInt();

                                System.out.print("Enter quantity for sour cream: ");

                                int sour_cream = scanner.nextInt();

                                System.out.print("Enter quantity for black olives: ");

                                int black_olives = scanner.nextInt();

                                System.out.print("Enter customer name: ");

                                String customerName = scanner.next();

                                /**

                                * Creating a burrito supreme using parameterized constructor

                                */

                                BurritoSupreme b1 = new BurritoSupreme(beans, beef, cheese, salsa,

                                                                customerName, sour_cream, black_olives);

                                b1.print_order();

                                System.out.println("The burrito weighs " + b1.weight() + " ounces");

                                b1.gutBuster();

                                b1.print_order();

                                System.out.println("The burrito weighs " + b1.weight() + " ounces");

                }

}

/*OUTPUT*/

No Name's burrito will be made of:

2 ounce(s) of beans

1 ounce(s) of beef

1 ounce(s) of cheese

1 ounce(s) of salsa

1 ounce(s) of sour cream

1 ounce(s) of black olives

The burrito weighs 7 ounces

Invoking the Gut Buster Special!!!

No Name's burrito will be made of:

4 ounce(s) of beans

2 ounce(s) of beef

2 ounce(s) of cheese

2 ounce(s) of salsa

2 ounce(s) of sour cream

2 ounce(s) of black olives

The burrito weighs 14 ounces

Creating a Burrito supreme from user input

Enter quantity for beans: 2

Enter quantity for beef: 3

Enter quantity for cheese: 5

Enter quantity for salsa: 4

Enter quantity for sour cream: 3

Enter quantity for black olives: 2

Enter customer name: Alice

Alice's burrito will be made of:

2 ounce(s) of beans

3 ounce(s) of beef

5 ounce(s) of cheese

4 ounce(s) of salsa

3 ounce(s) of sour cream

2 ounce(s) of black olives

The burrito weighs 19 ounces

Invoking the Gut Buster Special!!!

Alice's burrito will be made of:

4 ounce(s) of beans

6 ounce(s) of beef

10 ounce(s) of cheese

8 ounce(s) of salsa

6 ounce(s) of sour cream

4 ounce(s) of black olives

The burrito weighs 38 ounces

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