面向对象程序设计实验指导书6_第1页
面向对象程序设计实验指导书6_第2页
面向对象程序设计实验指导书6_第3页
面向对象程序设计实验指导书6_第4页
已阅读5页,还剩42页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、面向对象程序设计实验指导书黄利萍刘国奇东北大学软件学院2018.9目 录面向对象程序设计11/47实验指导书1前言 2实验要求3Experiment 1 Implementing the Collections in the Gourmet Coffee System ( 4 Hours )错误!未定义书签。Background错误!未定义书签。Description错误!未定义书签。Files 错误!未定义书签。Tasks 错误!未定义书签。Experiment 2 Using Design Patterns in the Gourmet Coffee System ( 4 Hours )错

2、误!未定义书签。Background错误!未定义书签。Description错误!未定义书签。Files 错误!未定义书签。Tasks 错误!未定义书签。Experiment 3 Using File I/O in the Gourmet Coffee System ( 4 Hours )错误!未定义书签。Background错误!未定义书签。Description错误!未定义书签。Files 错误!未定义书签。Tasks 错误!未定义书签。Experiment 4 Implementing a GUI for the Gourmet Coffee System ( 4 Hours )错误!未

3、定义书签。Background错误!未定义书签。Description错误!未定义书签。Files 错误!未定义书签。Tasks 错误!未定义书签。前 言面向对象的思想可以渗透到需求分析、系统建模、体系结构设计、程序设计与实现、系统测试等多个方面,它是描述现实世界复杂对象的相当直接而且直观的有效手段,对于提高系统质量、开发效率和代码重用率,都有明显的效果。面向对象程序设计课程是软件工程专业的重要专业基础课程之一,该门课程注重实践性和实用性,主要通过面向对象程序设计思想和Java语言结合起来,让学生掌握面向对象程序设计思想,以及熟练使用Java语言进行面向对象的编程,因此学生不能满足于只听懂老师

4、讲授的课堂内容,看懂书上的程序,应将课堂教案与实践环节紧密结合,使得学生加深对讲授内容的理解,学会上机调试程序。也就是善于发现程序中的错2/47误,并且能很快地排除这些错误,使程序能正确运行。面向对象程序设计是结合卡耐基梅隆大学的SSD3而形成的课程,该课程的教案体系和实验体系都很完整,并且东北大学软件学院也提供了良好的教案实验环境,希望同学们能够充分利用实验条件,认真完成实验,从实验中得到应有的锻炼和培养。希望同学们在使用本实验指导书及进行实验的过程中,能够帮助我们不断地发现问题,并提出建议,使面向对象程序设计真正能够帮助同学们学习。实验要求面向对象程序设计课程实验的目的是为了使学生在课堂学

5、习的同时,通过一系列的实验,使学生加深了解和更好地掌握面向对象程序设计课程教案大纲要求的内容。在面向对象程序设计的课程实验过程中,要求学生做到:( 1)预习实验指导书有关部分,认真做好实验内容的准备,就实验可能出现的情况提前作出思考和分析。( 2)仔细观察调试程序过程中出现的各种问题,记录主要问题,作出必要说明和分析。( 3)遵守机房纪律,服从辅导教师指挥,爱护实验设备。3/47( 4)实验课程不迟到,如有事不能出席,所缺实验一般不补。( 5)本实验采用的开发环境为 Eclipse ,同学在做实验之前要求熟悉该集成开发环境。Experiment1ImplementingtheGourmetCo

6、ffeeSystem(4 Hours)Prerequisites, Goals, and OutcomesPrerequisites:Before you begin this exercise, you need mastery of the following:Object Oriented Programmingo Knowledge of class designClass attributesConstructorsAccessor methodsMutator methodso Knowledge of inheritanceHow to implement a specializ

7、ation/generalizationrelationship using inheritanceGoals:Reinforce your ability to implement Java classes using inheritance.Outcomes:You will demonstrate mastery of the following:Implementing the constructors, accessors, and mutators of a Java classUsing inheritance to implement a specialization/gene

8、ralization relationshipBackgroundThis assignment asks you to implement some of the classes in theGourmet Coffee Systemspecified on Exercise 2.DescriptionIn this assessment, you will implement the classes and relationships illustrated in the following class diagram:4/47Figure 1Portion of Gourmet Coff

9、ee System class diagramThe class specifications are as follows:ClassProductThe classProduct models a generic product in the store.Instance variables:code. The unique code that identifies the productdescription. A short description of the productprice . The price of the productConstructor and methods

10、:public Product(String initialCode,String initialDescription,double initialPrice)Constructor that initializes the instance variablescode, description, andprice .5/47public String getCode(). Returns the value of instance variablecode.public String getDescription(). Returns the value of instance varia

11、bledescription.public double getPrice(). Returns the value of instance variableprice .boolean equals(Object object). Overrides the methodequals in the classObject . Two Product objects are equal if their codes are equal.String toString(). Overrides the methodtoStringReturns the string representation

12、 of aProduct object. Thethe following format:code_description_pricein the class Object . String returned hasThe fields are separated by an underscore (_ ). You can assume that the fieldsthemselves do not contain any underscores.ClassCoffeeThe classCoffee models a coffee product. It extends classProd

13、uct .Instance variables:origin. The origin of the coffeeroast . The roast of the coffeeflavor. The flavor of the coffeearoma. The aroma of the coffeeacidity. The acidity of the coffeebody. The body of the coffeeConstructor and methods:public Coffee(String initialCode,String initialDescription,double

14、 initialPrice,String initialOrigin,String initialRoast,String initialFlavor,String initialAroma,String initialAcidity,String initialBody)Constructor that initializes the instance variablescode, description, price ,origin, roast , flavor, aroma, acidity, andbody.6/47public String getOrigin(). Returns

15、 the value of instance variableorigin.public String getRoast(). Returns the value of instance variableroast .public String getFlavor(). Returns the value of instance variableflavor.public String getAroma(). Returns the value of instance variablearoma.public String getAcidity(). Returns the value of

16、instance variableacidity .public String getBody(). Returns the value of instance variableString toString(). Overrides the methodtoStringin the classReturns the string representation of aCoffeeobject. TheStringthe following format:body.Object .returned hascode_description_price _origin_roast _flavor_

17、aroma_acidity_bodyThe fields are separated by an underscore (_ ). You can assume that the fieldsthemselves do not contain any underscores.ClassCoffeeBrewerClass CoffeeBrewer models a coffee brewer. It extends classProduct .Instance variables:model. The model of the coffee brewerwaterSupply . The wat

18、er supply (Pour-over or Automatic )numberOfCups. The capacity of the coffee brewerConstructor and methods:public CoffeeBrewer(String initialCode,String initialDescription,double initialPrice,String initialModel,String initialWaterSupply,int initialNumberOfCups)Constructor that initializes the instan

19、ce variablescode description,price, and.model waterSupplynumberOfCupspublic String getModel(). Returns the value of instance variablemodel.7/47public String getWaterSupply(). Returns the value of instance variablewaterSupply .public int getNumberOfCups(). Returns the value of instance variablenumber

20、OfCups.String toString(). Overrides the methodtoStringin the classObject .Returns the string representation of aCoffeeBrewer object. TheStringreturned has the following format:code_description_price _model_waterSupply _numberOfCupsThe fields are separated by an underscore (_ ). You can assume that t

21、he fieldsthemselves do not contain any underscores.ClassOrderItemClass OrderItem models an item in an order.Instance variables:product . This instance variable represents the one-way association betweenOrderItem and Product . It contains a reference to aProduct object.quantity. The quantity of the p

22、roduct in the order.Constructor and methods:public OrderItem(Product initialProduct,int initialQuantity)Constructor that initializes the instance variablesproduct and quantity .public Product getProduct(). Returns the value of the instance variableproduct , a reference to aProduct object.public int

23、getQuantity(). Returns the value of the instance variablequantity .public void setQuantity(int newQuantity). Sets the instance variablequantityto the value of parameternewQuantity .public double getValue(). Returns the product ofquantity and price .8/47String toString(). Overrides the methodtoString

24、in the classObject .Returns the string representation of anOrderItem object. TheStringrepresentation has the following format:quantityproduct-codeproduct-priceThe fields are separated by a space. You can assume that the fields themselves do not contain any spaces.Test driver classesComplete implemen

25、tations of the following test drivers are provided in the student archive.Use these test drivers to verify that your code works correctly.ClassClassClassClassTestProductTestCoffeeTestCoffeeBrewerTestOrderItemFilesThe following files are needed to complete this assignment:student-files.zip Download t

26、his file. This archive contains the following:o TestProduct.javao TestCoffee.javao TestCoffeeBrewer.java o TestOrderItem.javaTasksImplement classesProduct , Coffee , CoffeeBrewer , andOrderItem . Document usingJavadoc and follow Sun's code conventions. The following steps will guide you through

27、thisassignment. Work incrementally and test each increment. Save often.1.Extractthe files by issuing the following command at the command prompt:C:>unzip student-files.zip2.Then , implement classProduct from scratch.UseTestProduct driver to testyour implementation.3.Next , implement classCoffee f

28、rom scratch.UseTestCoffee driver to test yourimplementation.9/474.Then, implement classCoffeeBrewer from scratch. UseTestCoffeeBrewerdriver to test your implementation.5.Finally, implement classOrderItem from scratch. UseTestOrderItem driver totest your implementation.SubmissionUpon completion, subm

29、itonlythe following:1. Product.java2. Coffee.java3. CoffeeBrewer.java4. OrderItem.javaExperiment2ImplementingtheCollectionsintheGourmet Coffee System (4 Hours)Prerequisites, Goals, and OutcomesPrerequisites:Before you begin this exercise, you need mastery of the following:CollectionsoUse of classArr

30、ayListo Use of iteratorsGoals:Reinforce your ability to implement classes that use collectionsOutcomes:You will demonstrate mastery of the following:Implementing a Java class that uses collectionsBackgroundIn this assignment, you will implement the classes in theGourmet Coffee Systemthat usecollecti

31、ons.DescriptionThe following class diagram of theGourmet Coffee Systemhighlights the classes that usecollections:10/47Figure 2 Gourmet Coffee System class diagramComplete implementations of the following classes are provided in the student archive:CoffeeCoffeeBrewerProductOrderItemGourmetCoffeeIn th

32、is assignment, you will implement the following classes:CatalogOrderSalesGourmetCoffee11/47The class specifications are as follows:ClassCatalogThe classCatalog models a product catalog. This class implements the interfaceIterable<Product> to being able to iterate through the products using the

33、for-eachloop.Instance variables:products AnArrayListcollection that contains references to instances ofclass Product .Constructor and public methods:public Catalog() Creates the collectionproducts, which is initially empty.public void addProduct(Product product) Adds the specified productto the coll

34、ectionproducts.public Iterator<Product> iterator() Returns an iterator over theinstances in the collectionproducts .public Product getProduct(String code) Returns a reference to theProduct instance with the specified code. Returnsnullif there are no productsin the catalog with the specified co

35、de.public int getNumberOfProducts() Returns the number of instances inthe collectionproducts .ClassOrderThe classOrder maintains a list of order items. This class implements the interfaceIterable<OrderItem>to being able to iterate through the items using thefor-eachloop.Instance variables:item

36、s An ArrayListcollection that contains references to instances of classOrderItem .Constructor and public methods:public Order() Creates the collectionitems , which is initially empty.12/47public void addItem(OrderItem orderItem) Adds the specified orderitem to the collectionitems .public void remove

37、Item(OrderItem orderItem) Removes the specifiedorder item from the collectionitems .public Iterator<OrderItem> iterator() Returns an iterator over theinstances in the collectionitems .public OrderItem getItem(Product product) Returns a reference totheOrderItem instance with the specified produ

38、ct. Returnsnull if there are noitems in the order with the specified product.public int getNumberOfItems() Returns the number of instances in thecollectionitems .public double getTotalCost() Returns the total cost of the order.ClassSalesThe classSales maintains a list of the orders that have been co

39、mpleted. This classimplements the interfaceIterable<Order>to being able to iterate through the ordersusing thefor-eachloop.Instance variables:orders An ArrayListcollection that contains references to instances of classOrder .Constructor and public methods:public Sales() Creates the collectiono

40、rders , which is initially empty.public void addOrder(Order order) Adds the specified order to thecollectionorders .public Iterator<Order> iterator() Returns an iterator over theinstances in the collectionorders .public int getNumberOfOrders() Returns the number of instances in thecollectionor

41、ders .ClassGourmetCoffeeThe class GourmetCoffee creates a console interface to process store orders. Currently, it includes the complete implementation of some of the methods. The methods13/47public void addModifyProduct()displayNumberOfOrders and displayTotalQuantityOfProductsare incompleteand shou

42、ld be implemented. The following is a screen shot of the interface:Figure 3 Execution of GourmetCoffeeInstance variables:catalog A Catalog object with the products that can be sold.currentOrder An Order object with the information about the current order.sales A Sales object with information about a

43、ll the orders sold by the store.Constructor and public methods:public GourmetCoffeeSolution() Initializes the attributescatalog ,currentOrder and sales . This constructor is complete and should not bemodified.public void displayCatalog Displays the catalog. This method iscomplete and should not be m

44、odified.public void displayProductInfo() Prompts the user for a product codeand displays information about the specified product. This method is complete and should not be modified.public void displayOrder() Displays the products in the current order.This method is complete and should not be modifie

45、d. Prompts the user for a product code andquantity. If the specified product is not already part of the order, it is added。otherwise, the quantity of the product is updated. This method is complete andshould not be modified.public void removeProduct() Prompts the user for a product code andremoves t

46、he specified product from the current order. This method is complete and should not be modified.14/47public void saleOrder() Registers the sale of the current order. Thismethod is complete and should not be modified.public void displayOrdersSold() Displays the orders that have beensold. This method

47、is complete and should not be modified.public void displayNumberOfOrders(Product product) Displays thenumber of orders that contain the specified product. This method is incompleteand should be implemented.public void displayTotalQuantityOfProducts() Displays the totalquantity sold for each product

48、in the catalog. This method is incomplete and should be implemented.Test driver classesComplete implementations of the following test drivers are provided in the student archive:ClassClassClassTestCatalogTestOrderTestSalesFilesThe following files are needed to complete this assignment:student-files.

49、zip Download this file. This archive contains the following:o Class filesCoffee.classCoffeeBrewer.classProduct.classOrderItem.classo DocumentationCoffee.htmlCoffeeBrewer.htmlProduct.htmlOrderItem.htmlo Java filesGourmetCoffee.java An incomplete implementation.TestCatalog.java A complete implementation.TestOrder.java A complete implemen

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论