Question: 1 Step I: Pizza Class Create a class named Pizza that stores information about a single pizza. It should contain the following: Private instance variables

1 Step I: Pizza Class 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 cheese toppings, the number of pepperoni toppings, and the number of ham toppings.

Constructor(s) that set all of the instance variables.

Public methods to get and set the instance variables.

A public method named calcCost( ) that returns a double that is the cost of the pizza. Pizza cost is determined by: Small: $10 + $2 per topping Medium: $12 + $2 per topping Large: $14 + $2 per topping

A public method named getDescription() that returns a String contain- ing the pizza size, quantity of each topping, and the pizza cost as calculated by calcCost().

Write test code to create several pizzas and output their descriptions. For example, a large pizza with one cheese, one pepperoni and two ham toppings should cost a total of $22.

2 Step II: PizzaOrder Class

Create a PizzaOrder class that allows up to three pizzas to be saved in an order. Each pizza saved should be a Pizza object as described in step I. It should contain the following:

Private instance variables to store the number of the pizza, three Pizza objects: pizza1, pizza2, pizza3

Constructor(s) that set all of the instance variables. In addition to appropriate instance variables and constructors, add the following methods: public void setNumPizzas(int numPizzas) sets the number of pizzas in the order. numPizzas must be between 1 and 3.

public void setPizza1(Pizza pizza1) sets the rst pizza in the order.

public void setPizza2(Pizza pizza2) sets the second pizza in the order. public void setPizza3(Pizza pizza3) sets the third pizza in the order.

public double calcTotal() returns the total cost of the order. Write a main method to test the class. The setPizza2 and setPizza3 methods will be used only if there are two or three pizzas in the order, respectively. Sample code illustrating the methods is shown below. Note that rst three lines are incomplete. You must complete them as part of the Programming Project. Pizza pizza1 = // Code to create a large pizza, 1 cheese, 1 ham Pizza pizza2 = // Code to create a medium pizza, 2 cheese, 2 pepperoni PizzaOrder order = // Code to create an order order.setNumPizzas(2); // 2 pizzas in the order order.setPizza1(pizza1); // Set first pizza order.setPizza2(pizza2); // Set second pizza double total = order.calcTotal(); // Should be 18+20 = 38

3 Step III: PizzaOrder Class Step II asked you to create a PizzaOrder class that stores an order consisting of up to three pizzas. Extend this class with the following methods and constructor: public int getNumPizzas() returns the number of pizzas in the order. public Pizza getPizza1() returns the rst pizza in the order or null if pizza1 is not set. public Pizza getPizza2() returns the second pizza in the order or null if pizza2 is not set. 2 public Pizza getPizza3() returns the third pizza in the order or null if pizza3 is not set. A copy constructor that takes another PizzaOrder object and makes an independent copy of its pizzas. This might be useful if using an old order as a starting point for a new order. Write a main method to test the new methods. Changing the pizzas in the new order should not change the pizzas in the original order. For example, Pizza pizza1 = // Code to create a large pizza, 1 cheese, 1 ham Pizza pizza2 = // Code to create a medium pizza, 2 cheese, 2 pepperoni PizzaOrder order1 = // Code to create an order order1.setNumPizzas(2); // 2 pizzas in the order order1.setPizza1(pizza1); // Set first pizza order1.setPizza2(pizza2); // Set second pizza double total = order1.calcTotal(); // Should be 18+20 = 38 PizzaOrder order2 = new PizzaOrder(order1); // Use copy constructor order2.getPizza1().setNumCheeseToppings(3); // Change toppings double total = order2.calcTotal(); // Should be 22 + 20 = 42 double origTotal = order1.calcTotal(); // Should still be 38 Note that the rst three lines of code are incomplete. You must complete them as part of the Programming Project.

4 Submission Run your program make sure it is working correctly. Please submit your source les: Pizza.java and PizzaOrder.java

NEED TO RUN THIS CODE ON ECLIPSE WITH JAVA AS PROGRAMMING LANGUAGE .................. COULD YOU PLEASE GIVE ME U EMAIL ID WHILE POSTING U ANS SO IF I GOT ERROR I COUD SEND IT TO U DIRECTLY WHAT THE PROBLEM IS THXXXX

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!