Java Reference
In-Depth Information
public void setPizza1(Pizza pizza1) —sets the first 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 first three lines are incom-
plete. 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
13. Your Community Supported Agriculture (CSA) farm delivers a box of fresh fruits
and vegetables to your house once a week. For this Programming Project, define
the class BoxOfProduce that contains exactly three bundles of fruits or vegetables.
You can represent the fruits or vegetables as three instance variables of type String .
Add an appropriate constructor, accessor, and mutator methods. Also write a
toString() method that returns as a String the complete contents of the box.
Next, write a main method that creates a BoxOfProduce with three items randomly
selected from this list:
Broccoli
Tomato
Kiwi
Kale
Tomatillo
This list should be stored in a text file that is read in by your program. For now
you can assume that the list contains exactly five types of fruits or vegetables.
Do not worry if your program randomly selects duplicate produce for the three
items. Next, the main method should display the contents of the box and allow
the user to substitute any one of the five possible fruits or vegetables for any of the
fruits or vegetables selected for the box. After the user is done with substitutions,
output the final contents of the box to be delivered. If you create additional meth-
ods to select the random items and to select valid substitutions, then your main
method will be simpler to write.
Search WWH ::




Custom Search