Java Reference
In-Depth Information
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 first three lines of code are incomplete. You must complete them as
part of the Programming Project.
9 . U s e javadoc to generate HTML documentation for the code in Display 5.19.
Use the @author and @version tag for the description of the entire class. Add a
comment for every public method or constructor using the @param and @return
tags when appropriate.
10. First, complete Programming Project 4.13 from Chapter 4 .
VideoNote
Solution to
Programming
Project 5.9
Modify the main method with a loop so that an arbitrary number of BoxOfProduce
objects are created and substitutions are allowed for each box. Add a menu so the
user can decide when to stop creating boxes.
You would like to throw in a free recipe flyer for salsa verde if the box contains
tomatillos. However, there are only five recipe flyers. Add a static variable to the
BoxOfProduce class that counts the number of recipe flyers remaining and initialize
it to 5. Also add an instance variable that indicates whether or not the box contains
a recipe flyer and modify the toString() method to also output “ salsa verde
recipe ” if the box contains a recipe flyer. Finally, add logic inside the class so that
if the box contains at least one order of tomatillos then it automatically gets a recipe
flyer until all of the recipe flyers are gone. Note that a box should only get one recipe
flyer even if there are multiple orders of tomatillos.
Test your class by creating boxes with tomatillos from your menu until all of the
flyers are gone.
Search WWH ::




Custom Search