/** * This class describes items that might go on a pizza. * Note: the default constructor defines an item 'nothing' * * * @author Dave Slemon * @version v100 */ public class Item { private String name; private double cost; /** * * The default constructor is a special 'nothing' item. * */ public Item() { this.cost = 0.0; this.name = ""; } /** * * This constructor lets you create a pizza item and * supply it's cost. * * @param name the name */ public Item(String name) { this.name = name.toLowerCase(); this.cost = calculateCost (name); } /** * * This setter lets you take a default item and give it * a name. (e.g. anchovies ) * * @param name the name of pizza item */ public void setName(String name) { this.name = name; this.cost = calculateCost (name); } /** * * This getter lets you get the name of the item. * * @return the name of the item */ public String getName() { return name; } /** * * Gets the cost of this particular item * * @return the cost of the item */ public double getCost() { return cost; } /** * * Calculate cost of an item from the lookup table * below * * @param itemName the name of a pizza item name * @return double which is the cost of the item. */ private double calculateCost (String itemName) { String topping = itemName.toLowerCase(); if (topping.equals("mushrooms") ) return 1.20; else if (topping.equals("pepperoni") ) return 1.00; else if (topping.equals("green peppers") ) return 0.90; else if (itemName.length() > 0) return 1.00; return 0.00; } /** * * Display's the item and it's cost. * * @return String */ public String toString() { return String.format("%s is $%.2f",getName(),getCost()); } }