/** * This class represents a pizza with at most 3 items. * * @author Dave Slemon * @version v100 */ public class Pizza { //instance variables private String size; private Item item1; private Item item2; private Item item3; /** * * This constructor builds a basic pizza, * * @param size the size of the pizza, LARGE, MEDIUM or SMALL */ public Pizza( String size ) { this.size = size; item1 = new Item(); //the default constructor places no items on the pizza item2 = new Item(); item3 = new Item(); } /** * * This setter allows you to place at most 3 items onto the pizza. * NOTE: the default Item() means 'no item' * * @param topping1 the 1st item topping * @param topping2 the 2nd item topping * @param topping3 the 3rd item topping */ public void setToppings(Item topping1, Item topping2, Item topping3) { item1= topping1; item2= topping2; item3= topping3; } /** * * Gets the cost of the pizza including its items * * @return the cost total cost of the pizza */ public double getCost() { double amt = 0.0; String type = size.toLowerCase(); if (type.equals("large") ) amt = 7.00; else if (type.equals("medium") ) amt = 5.00; else if (type.equals("small") ) amt = 3.00; else amt = 0.0; amt = amt + item1.getCost()+item2.getCost()+item3.getCost(); return amt; } public String getSize() { return this.size; } public void setSize(String size) { this.size = size.toLowerCase(); } /** * * Outputs the size of the pizza and its toppings * * @return String a text describing the pizza */ public String toString() { String output = size + " - " + item1.getName() + " " + item2.getName() + " " + item3.getName(); return output; } }