您好,欢迎访问三七文档
当前位置:首页 > 机械/制造/汽车 > 汽车理论 > ssd3-实验完整答案-一、二
ImplementingtheGourmetCoffeeSystem代码publicclassProduct{privateStringcode;privateStringdescription;privatedoubleprice;publicProduct(StringinitialCode,StringinitialDescription,doubleinitialPrice){this.code=initialCode;this.description=initialDescription;this.price=initialPrice;}publicStringgetCode(){returncode;}publicStringgetDescription(){returndescription;}publicdoublegetPrice(){returnprice;}publicbooleanequals(Objectobject){return(objectinstanceofProduct)&&((Product)object).getCode()==this.getCode();}publicStringtoString(){returngetCode()+_+getDescription()+_+getPrice();}}publicclassCoffeeextendsProduct{privateStringorigin;privateStringroast;privateStringflavor;privateStringaroma;privateStringacidity;privateStringbody;publicCoffee(StringinitialCode,StringinitialDescription,doubleinitialPrice,StringinitialOrigin,StringinitialRoast,StringinitialFlavor,StringinitialAroma,StringinitialAcidity,StringinitialBody){super(initialCode,initialDescription,initialPrice);this.origin=initialOrigin;this.roast=initialRoast;this.flavor=initialFlavor;this.aroma=initialAroma;this.acidity=initialAcidity;this.body=initialBody;}publicStringgetOrigin(){returnorigin;}publicStringgetRoast(){returnroast;}publicStringgetFlavor(){returnflavor;}publicStringgetAroma(){returnaroma;}publicStringgetAcidity(){returnacidity;}publicStringgetBody(){returnbody;}publicStringtoString(){returngetCode()+_+getDescription()+_+getPrice()+_+getOrigin()+_+getRoast()+_+getFlavor()+_+getAroma()+_+getAcidity()+_+getBody();}}publicclassCoffeeBrewerextendsProduct{privateStringmodel;privateStringwaterSupply;privateintnumberOfCups;publicCoffeeBrewer(StringinitialCode,StringinitialDescription,doubleinitialPrice,StringinitialModel,StringinitialWaterSupply,intinitialNumberOfCups){super(initialCode,initialDescription,initialPrice);this.model=initialModel;this.waterSupply=initialWaterSupply;this.numberOfCups=initialNumberOfCups;}publicStringgetModel(){returnmodel;}publicStringgetWaterSupply(){returnwaterSupply;}publicintgetNumberOfCups(){returnnumberOfCups;}publicStringtoString(){returngetCode()+_+getDescription()+_+getPrice()+_+getModel()+_+getWaterSupply()+_+getNumberOfCups();}}publicclassOrderItem{Productproduct;privateintquantity;publicOrderItem(ProductinitialProduct,intinitialQuantity){this.product=initialProduct;this.quantity=initialQuantity;}publicProductgetProduct(){returnproduct;}publicintgetQuantity(){returnquantity;}publicvoidsetQuantity(intnewQuantity){this.quantity=newQuantity;}publicdoublegetValue(){returnproduct.getPrice()*this.getQuantity();}publicStringtoString(){returngetQuantity()++product.getCode()++product.getPrice();}}importjava.util.ArrayList;importjava.util.Iterator;publicclassCatalogimplementsIterableProduct{privateArrayListProductproducts;publicCatalog(){products=newArrayListProduct();}publicvoidaddProduct(Productproduct){products.add(product);}publicIteratorProductgetProductsIterator(){returnproducts.iterator();}publicProductgetProduct(Stringcode){for(Productpro:products){if(pro.getCode().equals(code))returnpro;}returnnull;}publicintgetNumberOfProducts(){returnproducts.size();}publicIteratorProductiterator(){returnthis.getProductsIterator();}}importjava.util.ArrayList;importjava.util.Iterator;publicclassOrderimplementsIterableOrderItem{privateArrayListOrderItemitems;publicOrder(){items=newArrayListOrderItem();}publicvoidaddItem(OrderItemorderItem){items.add(orderItem);}publicvoidremoveItem(OrderItemorderItem){items.remove(orderItem);}publicIteratorOrderItemgetItemsIterator(){returnitems.iterator();}publicOrderItemgetItem(Productproduct){for(OrderItemord:items){if(ord.getProduct().equals(product))returnord;}returnnull;}publicintgetNumberOfItems(){returnitems.size();}publicIteratorOrderItemiterator(){returnthis.getItemsIterator();}publicdoublegetTotalCost(){doubletotalCost=0;for(OrderItemord:items){totalCost+=ord.getValue();}returntotalCost;}}importjava.util.ArrayList;importjava.util.Iterator;publicclassSalesimplementsIterableOrder{privateArrayListOrderorders;publicSales(){orders=newArrayListOrder();}publicvoidaddOrder(Orderorder){orders.add(order);}publicIteratorOrdergetOrdersIterator(){returnorders.iterator();}publicintgetNumberOfOrders(){returnorders.size();}publicIteratorOrderiterator(){returnorders.iterator();}}importjava.io.*;importjava.text.*;/***Thisclassimplementsagourmetcoffeesystem.**@authorauthorname*@version1.1.0*@seeProduct*@seeCoffee*@seeCoffeeBrewer*@seeCatalog*@seeOrderItem*@seeOrder*/publicclassGourmetCoffee{privatestaticBufferedReaderstdIn=newBufferedReader(newInputStreamReader(System.in));privatestaticPrintWriterstdOut=newPrintWriter(System.out,true);privatestaticPrintWriterstdErr=newPrintWriter(System.err,true);privatestaticfinalNumberFormatCURRENCY=NumberFormat.getCurrencyInstance();privateCatalogcatalog;privateOrdercurrentOrder;privateSalessales;/***Loadsdataintothecatalogandstartstheapplication.**@paramargsStringarguments.Notused.*@throwsIOExceptionifthereareerrorsintheinput.*/publicstat
本文标题:ssd3-实验完整答案-一、二
链接地址:https://www.777doc.com/doc-4739989 .html