Question: Create a Copy Constructor for both the PizzaOrder class and Pizza class ( I am struggling handling the array of Pizzas). public class PizzaOrder {

Create a Copy Constructor for both the PizzaOrder class and Pizza class ( I am struggling handling the array of Pizzas).

public class PizzaOrder {

private static final int MAX_NUM_PIZZAS = 5; private Pizza[] pizza; private int numPizzas;

public PizzaOrder() { pizza = new Pizza[MAX_NUM_PIZZAS]; numPizzas = 0; }

public PizzaOrder(PizzaOrder original) //Copy Constructor { pizza = new Pizza(original.pizza[]);/////Fix this numPizzas = original.numPizzas; } /* * Adds a pizza to the order */ public void addPizza(Pizza p) { if (numPizzas >= MAX_NUM_PIZZAS) { System.out.println("Too many pizzas for this order"); } else { pizza[numPizzas] = p; numPizzas++; }

}

}

}

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

public class Pizza {

public static final String SMALL = "Small"; public static final String MEDIUM = "Medium"; public static final String LARGE = "Large";

private String size; private int numCheeseToppings; private int numHamToppings; private int numPepperoniToppings;

// no argument constructor public Pizza() { size = "Large"; numCheeseToppings = 1; numHamToppings = 0; numPepperoniToppings = 0; }

/* * Constructor takes 4 arguments: size of pizza, num of cheese toppings, * num of ham toppings, num of pepperoni toppings */ public Pizza(String pizzaSize, int cheese, int ham, int pepperoni) { if (!(pizzaSize == SMALL || pizzaSize == MEDIUM || pizzaSize == LARGE)) { // if size is invalid, set size to SMALL size = SMALL; } else { size = pizzaSize; } numCheeseToppings = cheese; numHamToppings = ham; numPepperoniToppings = pepperoni; }

}

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!