Question

Take the Pizza class from assignment # 1 and modify it in the following way: - Rename it to DeluxePizza. - Add a stuffedWithC
0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question.

Here is the completed code for this problem. Would have been better if you would have shared the Pizza class already written for reference, nevertheless let me know if you have any doubts or if you need anything to change.

Thank You !!

Please Note: There are 3 more instance variables from the Pizza class that you need to add to the overloaded constructor.

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


public class DeluxePizza {

    private boolean stuffedWithCheese;
    private int veggieTopping;
    private int size;
    private static int numberOfPizzas;

    public DeluxePizza() {
        this.stuffedWithCheese = false;
        this.veggieTopping = 0;
        this.size = 0;
        numberOfPizzas += 1;
    }

    public DeluxePizza(boolean stuffed, int topping, int size) {
        this.stuffedWithCheese = stuffed;
        this.veggieTopping = topping;
        this.size = size;
        numberOfPizzas += 1;
    }

    public DeluxePizza(DeluxePizza pizza) {
        this.stuffedWithCheese = pizza.stuffedWithCheese;
        this.veggieTopping = pizza.veggieTopping;
        numberOfPizzas += 1;
    }

    public int getVeggieTopping() {
        return veggieTopping;
    }

    public boolean isStuffedWithCheese() {
        return stuffedWithCheese;
    }

    public static int getNumberOfPizzas() {
        return numberOfPizzas;
    }

    public double calcCost() {
        double cost = 3.0*veggieTopping;

        if (stuffedWithCheese) {
            if (size == 1) {
                cost += 2;
            } else if (size == 2) {
                cost += 4;
            } else if (size == 3) {
                cost += 6;
            }
        }
        return cost;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj != null && obj instanceof DeluxePizza) {
            DeluxePizza pizza = (DeluxePizza) obj;
            return stuffedWithCheese = pizza.isStuffedWithCheese() &&
                    this.veggieTopping == pizza.getVeggieTopping() &&
                    this.size == pizza.size;
        }
        return false;
    }

    @Override
    public String toString() {
        return "DeluxePizza " +
                "Stuffed With Cheese: " + stuffedWithCheese +
                ", Veggie Toppings: " + veggieTopping +
                ", Size: " + size +
                '}';
    }
}

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

t h a n k s !

Add a comment
Know the answer?
Add Answer to:
Take the Pizza class from assignment # 1 and modify it in the following way: -...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USE!! PYTHON!!! Programming:   Pizza 1. Write a Pizza class to that this client code works. Please...

    USE!! PYTHON!!! Programming:   Pizza 1. Write a Pizza class to that this client code works. Please note that it is ok if the toppings are listed in a different order. >>> pie = Pizza() >>> pie Pizza('M',set()) >>> pie.setSize('L') >>> pie.getSize() 'L' >>>pie.addTopping('pepperoni') >>>pie.addTopping('anchovies') >>>pie.addTopping('mushrooms') >>> pie Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'}) >>>pie.addTopping('pepperoni') >>> pie Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'}) >>>pie.removeTopping('anchovies') >>> pie Pizza('L',{'mushrooms', 'pepperoni'}) >>> pie.price() 16.65 >>> pie2 = Pizza('L',{'mushrooms','pepperoni'}) >>> pie2 Pizza('L',{'mushrooms', 'pepperoni'}) >>> pie==pie2 True The Pizza class should have...

  • Consider the class as partially defined here: //class Pizzaorder class Pizzaorder // static public members public...

    Consider the class as partially defined here: //class Pizzaorder class Pizzaorder // static public members public static final int MAX TOPPINGS 20: // instance members private String toppings[]; private int numToppings; // constructor public PizzaOrder () { numToppings toppings 0; String[MAX TOPPINGS]; new // accessor tells # toppings on pizza, i.e., #toppings in array public int getNum Toppings ()return numToppings; // etc. We want to write an instance method, addTopping) that will take a String parameter, topping, and add it...

  • using java write a code with notepad++ Create the following classes using inheritance and polymorphism Ship...

    using java write a code with notepad++ Create the following classes using inheritance and polymorphism Ship (all attributes private) String attribute for the name of ship float attribute for the maximum speed the of ship int attribute for the year the ship was built Add the following behaviors constructor(default and parameterized) , finalizer, and appropriate accessor and mutator methods Override the toString() method to output in the following format if the attributes were name="Sailboat Sally", speed=35.0f and year built of...

  • C# Programming Exercise and Bonus Exercise (Next Page) 1) Define a class called OrderPizza that has...

    C# Programming Exercise and Bonus Exercise (Next Page) 1) Define a class called OrderPizza that has member variables to track the type of pizza being order (either deep dish, hand tossed, or pan) along with the size (small, medium or large), type of toppings (pepperoni, cheese etc.) and the number of toppings. Create accessors for each property (ex.: type, size, type of toppings, and number of toppings). Implementation class should have a CalculateOrderPayment method to compute the total cost of...

  • You will need to first create an object class encapsulating a Trivia Game which INHERITS from...

    You will need to first create an object class encapsulating a Trivia Game which INHERITS from Game. Game is the parent class with the following attributes: description - which is a string write the constructor, accessor, mutator and toString methods. Trivia is the subclass of Game with the additional attributes: 1. trivia game id - integer 2. ultimate prize money - double 3. number of questions that must be answered to win - integer. 4. write the accessor, mutator, constructor,...

  • IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand...

    IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand the Application The assignment is to first create a class calledTripleString.TripleStringwill consist of threeinstance attribute strings as its basic data. It will also contain a few instance methods to support that data. Once defined, we will use it to instantiate TripleString objects that can be used in our main program. TripleString will contain three member strings as its main data: string1, string2, and string3....

  • Use inheritance to create a new class AudioRecording based on Recording class that: it will retain...

    Use inheritance to create a new class AudioRecording based on Recording class that: it will retain all the members of the Recording class, it will have an additional field bitrate (non-integer numerical; it cannot be modified once set), its constructors (non-parametrized and parametrized) will set all the attributes / fields of this class (reuse code by utilizing superclass / parent class constructors): Non-parametrized constructor should set bitrate to zero, If arguments for the parametrized constructor are illegal or null, it...

  • In this lab, you will be writing a complete class from scratch, the IceCreamCone class. You...

    In this lab, you will be writing a complete class from scratch, the IceCreamCone class. You will also write a driver to interact with a user and to test all of the IceCreamCone methods. Lab: • Cone • Ice Cream o Flavor o Topping • Ice Cream Cone • Driver Part I: Cone An ice cream cone has two main components, the flavor of ice cream and the type of cone. Write a Cone class that takes an integer in...

  • The Drive‑Rite Insurance Company provides automobile insurance policies for drivers. Design a single class diagram showing...

    The Drive‑Rite Insurance Company provides automobile insurance policies for drivers. Design a single class diagram showing the class, the application program, the relationship between the two, and multiplicity. Insert the completed class diagram into a Word document. Then write the pseudocode as described below. Be sure to follow the CSI 117 Style Criteria (Links to an external site.)Links to an external site. for naming conventions, class diagrams, pseudocode, keywords, and operators. a.      Create a PolicyHolder class that contains a policy number,...

  • Programming Assignment 1 Write a class called Clock. Your class should have 3 instance variables, one...

    Programming Assignment 1 Write a class called Clock. Your class should have 3 instance variables, one for the hour, one for the minute and one for the second. Your class should have the following methods: A default constructor that takes no parameters (make sure this constructor assigns values to the instance variables) A constructor that takes 3 parameters, one for each instance variable A mutator method called setHour which takes a single integer parameter. This method sets the value of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT