Question: Scoping and Multiple Constructors Create a class named Pizza that stores information about a single pizza. It should contain the following: Private instance variables to

Scoping and Multiple Constructors
Create a class named Pizza that stores information about a single pizza. It should contain the following:
Private instance variables to store the size of the pizza (either small, medium, or large), the number of meat toppings, the number of veggie toppings and whether or not the pizza should be vegan-friendly (in which case you must make sure that the number of meat toppings is 0). Discuss with your partner what the difference between a private and public instance variable is.
Constructorsthat set all of the instance variables. One constructor should be a no-arg constructor, with defaults of medium, no toppings, non-vegan. At least one other constructor should enable you to give all the private instance variables a value when you create the object. You should also include error checking to make sure the values you are setting are legitimate (e.g., there is no such a size pizza as "grande"). Discuss with your partner why there is more than one kind of constructor and when will each constructor be used.
Public methods to get and set the instance variables. Discuss with your partner what would happen if these methods were set to private and why these accessor and getter methods are needed.
A public method named calcCost that returns a double that is the cost of the pizza. Pizza cost is determined by:
Small: $10Medium: $12Large: $14Each meat topping cost $2 and each veggie topping cost $1If the pizza is vegan, it costs an additional $2
A public method named getDescription that returns a String containing the pizza size, whether it is vegan or not, quantity of each topping, and the pizza cost as calculated by calcCost.
Use the provided class named Pizzaria, (download from above) to test your Pizza class. The Pizzaria class provides test code to create several pizzas and outputs their descriptions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!