Question: JAVA PART A: modify the setSize(String size) method to set the size of the pizza only if the size passed in is small, medium, large,

JAVA

PART A: modify the setSize(String size) method to set the size of the pizza only if the size passed in is small, medium, large, extra large (ignoring the size).

Once you get into the method, immediately take the size to lowercase. Create an if statement that checks if the size is small or medium or large or extra large. If it is, set this.size = size. If not, assign this.size to be null.

Create a third pizza in the PizzaTester class called thirdPizza. Set the values to pepperoni, extra small, 7.99. Repeat the third pizza order using "repeatOrder()". Confirm that null displays for the pizza size.

PART B: In your pizza class, remove the default constructor. Only allow one constructor that requires the three parameters. Create a check in your constructor to see if size is null. If it is, throw an IllegalArgumentException and don't allow the pizza to be created.

In your PizzaTester class, you'll see an error that there's an issue with the myPizza constructor. Modify myPizza to be a large mushroom pizza for 9.99. Remove the set methods in the PizzaTester for myPizza since we set them with the constructor.

After it is working, test your class to make sure you get the exception when the thirdPizza is being created. Comment out (please keep it so I can see that you tried it) the line where you create the new thirdPizza and where you try to repeat the order for the thirdPizza.

PART C: add a new instance variable called orderNumber. Make it an integer. Create a getter only for orderNumber (the order number will only be set in the constructor so no point in creating a setter method).

Add a static instance variable called nextOrderNumber that starts at 1001. Hint: the word static will come between the access (private) and the data type (int).

In the constructor, increase nextOrderNumber by one. (nextOrderNumber++;) Then, set the value of this.orderNumber equal to the value in nextOrderNumber (just a simple equal sign will work).

Modify your repeatOrder() method to print out the orderNumber too. It should look something like this:

Pizza 1 info: Order number: 1002, Topping: mushroom, Size: large, Price: $9.99 Pizza 2 info: Order number: 1003, Topping: pepperoni, Size: extra large, Price: $13.99

public class Pizza { private String topping; private String size; private double price;

public Pizza() { setTopping("cheese"); setSize("large"); setPrice(9.99); }

public Pizza(String t, String s, double p) { setTopping(t); setSize(s); setPrice(p); }

public void setTopping(String topping) { this.topping = topping; }

public void setSize(String size) { this.size = size; }

public void setPrice(double price) { this.price = price; }

public String getTopping() { return topping; }

public String getSize() { return size; }

public double getPrice() { return price; }

public String repeatOrder() { String topping = this.getTopping(); String size = this.getSize(); double price = this.getPrice(); return "You ordered a " + size + topping + " pizza for $" + price; }

@Override public String toString() { return "Pizza [Topping=" + topping + ", Size=" + size + ", Price=" + price + "]"; }

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!