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 veganfriendly in which case you must make sure that the number of meat toppings is 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 noarg constructor, with defaults of medium, no toppings, nonvegan. 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 eg 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: $Medium: $Large: $Each meat topping cost $ and each veggie topping cost $If the pizza is vegan, it costs an additional $
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
