Question: Create a class called Pizza . It should have the following instance variables: Name of Instance variable Description of instance variable size Size of the

Create a class called Pizza. It should have the following instance variables:

Name of Instance variable

Description of instance variable

size

Size of the pizza. Expected values include S, M, L, or XL

numToppings

Number of toppings on the pizza

discountCode

String representing a discount code to be used

Create a constructor for Pizza which does not have any parameters. Set the size to S, number of toppings to 0, and discountCode = .

Create a constructor for Pizza which has 3 parameters. Use the parameter variables to set the instance variables.

Create the getters and setters for all of the instance variables

Create an instance method called computeSubtotal. There are no parameters to this method. It returns the price of the pizza based upon the pizza size and number of toppings as described below

Small pizzas: $5 each, Medium pizzas: $7 each, Large pizzas: $9 each, and XL pizzas: $12 each

Toppings are $.75 each

For example, Small, 2-topping pizza = 5 + 2*.75 = 6.50. Medium, 1-topping pizza = 7 + .75 = 7.75.

Create an instance method called computeDiscount. There are no parameters to this method. It returns the amount of the discount based upon the discount code.

Discount code of special returns 3.5. When comparing, ignore case.

Discount code of payless returns 4.25. When comparing, ignore case.

Otherwise, return 0.

Create an instance method called printReport. It should display the pizza size, number of toppings, discount code, subtotal, discount amount, and total due. Here are some examples of what this should look like:

Pizza size: S Pizza Size: L

Number of toppings : 2 Number of toppings : 0

Discount code: special Discount code: SPECIAL

------------------------------ -----------------------------

Subtotal: 6.5 Subtotal:9.0

Discount: 3.5 Discount: 3.5

Total due: 3.0 Total Due: 5.5

Create a class called PizzaTester. It should have a main method in it

Inside the main method, use the Scanner class for user input

Ask for the size of the pizza. Store response in a variable.

Ask for the discount code for the pizza. Store response in a variable.

Ask for number of toppings. Store response in a variable.

Use the information typed in, to create a Pizza object called myPizza.

Call the printReport method on myPizza

(Add appropriate comments (class, methods and variables). Poinst are allocated for comments)

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 Databases Questions!