1、public String getDescription() return description;public double getPrice() return price;public boolean equals(Object object) return (object instanceof Product) & (Product) object).getCode() = this.getCode();public String toString() return getCode() + _ + getDescription() + + getPrice();public class
2、Coffee extends Product private String origin;private String roast;private String flavor;private String aroma;private String acidity;private String body;public Coffee(String initialCode, String initialDescription, double initialPrice, String initialOrigin, String initialRoast, String initialFlavor, S
3、tring initialAroma, String initialAcidity, String initialBody) super(initialCode, initialDescription, initialPrice); this.origin = initialOrigin; this.roast = initialRoast; this.flavor = initialFlavor; this.aroma = initialAroma; this.acidity = initialAcidity; this.body = initialBody;public String ge
4、tOrigin() return origin;public String getRoast() return roast;public String getFlavor() return flavor;public String getAroma() return aroma;public String getAcidity() return acidity;public String getBody() return body; + getPrice() + + getOrigin() + + getRoast() + + getFlavor() + + getAroma() + + ge
5、tAcidity() + + getBody();public class CoffeeBrewer extends Product private String model;private String waterSupply;private int numberOfCups;public CoffeeBrewer(String initialCode, String initialDescription, double initialPrice, String initialModel, String initialWaterSupply, int initialNumberOfCups)
6、 this.model = initialModel; this.waterSupply = initialWaterSupply; this.numberOfCups = initialNumberOfCups;public String getModel() return model;public String getWaterSupply() return waterSupply;public int getNumberOfCups() return numberOfCups; + getModel() + + getWaterSupply() + + getNumberOfCups()
7、;public class OrderItem Product product;private int quantity;public OrderItem(Product initialProduct, int initialQuantity) this.product = initialProduct; this.quantity = initialQuantity;public Product getProduct() return product;public int getQuantity() return quantity;public void setQuantity(int ne
8、wQuantity) this.quantity = newQuantity;public double getValue() return product.getPrice() * this.getQuantity(); return getQuantity() + + product.getCode() + + product.getPrice();import java.util.ArrayList;import java.util.Iterator;public class Catalog implements Iterable private ArrayList products;p
9、ublic Catalog() products = new ArrayList();public void addProduct(Product product) products.add(product);public Iterator getProductsIterator() return products.iterator();public Product getProduct(String code) for (Product pro : products) if (pro.getCode().equals(code) return pro; return null;public
10、int getNumberOfProducts() return products.size(); iterator() return this.getProductsIterator();public class Order implements Iterable items;public Order() items = new ArrayListpublic void addItem(OrderItem orderItem) items.add(orderItem);public void removeItem(OrderItem orderItem) items.remove(order
11、Item); getItemsIterator() return items.iterator();public OrderItem getItem(Product product) for (OrderItem ord : items) if (ord.getProduct().equals(product) return ord;public int getNumberOfItems() return items.size(); return this.getItemsIterator();public double getTotalCost() double totalCost = 0; totalCost += ord.getValue(); return totalCost;public class Sales implements Iterable orders;public Sales() orders = new ArrayListpublic void addOrder(Order order) orders.add(order); getOrdersIterator() return orders.iterator();public int getNumberOfOrders
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1