面向对象程序设计实验指导书doc.docx

上传人:b****1 文档编号:15132876 上传时间:2023-07-01 格式:DOCX 页数:51 大小:435.11KB
下载 相关 举报
面向对象程序设计实验指导书doc.docx_第1页
第1页 / 共51页
面向对象程序设计实验指导书doc.docx_第2页
第2页 / 共51页
面向对象程序设计实验指导书doc.docx_第3页
第3页 / 共51页
面向对象程序设计实验指导书doc.docx_第4页
第4页 / 共51页
面向对象程序设计实验指导书doc.docx_第5页
第5页 / 共51页
面向对象程序设计实验指导书doc.docx_第6页
第6页 / 共51页
面向对象程序设计实验指导书doc.docx_第7页
第7页 / 共51页
面向对象程序设计实验指导书doc.docx_第8页
第8页 / 共51页
面向对象程序设计实验指导书doc.docx_第9页
第9页 / 共51页
面向对象程序设计实验指导书doc.docx_第10页
第10页 / 共51页
面向对象程序设计实验指导书doc.docx_第11页
第11页 / 共51页
面向对象程序设计实验指导书doc.docx_第12页
第12页 / 共51页
面向对象程序设计实验指导书doc.docx_第13页
第13页 / 共51页
面向对象程序设计实验指导书doc.docx_第14页
第14页 / 共51页
面向对象程序设计实验指导书doc.docx_第15页
第15页 / 共51页
面向对象程序设计实验指导书doc.docx_第16页
第16页 / 共51页
面向对象程序设计实验指导书doc.docx_第17页
第17页 / 共51页
面向对象程序设计实验指导书doc.docx_第18页
第18页 / 共51页
面向对象程序设计实验指导书doc.docx_第19页
第19页 / 共51页
面向对象程序设计实验指导书doc.docx_第20页
第20页 / 共51页
亲,该文档总共51页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

面向对象程序设计实验指导书doc.docx

《面向对象程序设计实验指导书doc.docx》由会员分享,可在线阅读,更多相关《面向对象程序设计实验指导书doc.docx(51页珍藏版)》请在冰点文库上搜索。

面向对象程序设计实验指导书doc.docx

面向对象程序设计实验指导书doc

面向对象程序设计

实验指导书

宋航刘国奇

 

东北大学软件学院

2012.9

前言

面向对象的思想可以渗透到需求分析、系统建模、体系结构设计、程序设计与实现、系统测试等多个方面,它是描述现实世界复杂对象的相当直接而且直观的有效手段,对于提高系统质量、开发效率和代码重用率,都有明显的效果。

《面向对象程序设计》课程是软件工程专业的重要专业基础课程之一,该门课程注重实践性和实用性,主要通过面向对象程序设计思想和Java语言结合起来,让学生掌握面向对象程序设计思想,以及熟练使用Java语言进行面向对象的编程,因此学生不能满足于只听懂老师讲授的课堂内容,看懂书上的程序,应将课堂教学与实践环节紧密结合,使得学生加深对讲授内容的理解,学会上机调试程序。

也就是善于发现程序中的错误,并且能很快地排除这些错误,使程序能正确运行。

《面向对象程序设计》是结合卡耐基梅隆大学的SSD3而形成的课程,该课程的教学体系和实验体系都很完整,并且东北大学软件学院也提供了良好的教学实验环境,希望同学们能够充分利用实验条件,认真完成实验,从实验中得到应有的锻炼和培养。

希望同学们在使用本实验指导书及进行实验的过程中,能够帮助我们不断地发现问题,并提出建议,使《面向对象程序设计》真正能够帮助同学们学习。

 

实验要求

《面向对象程序设计》课程实验的目的是为了使学生在课堂学习的同时,通过一系列的实验,使学生加深了解和更好地掌握《面向对象程序设计》课程教学大纲要求的内容。

在《面向对象程序设计》的课程实验过程中,要求学生做到:

(1)预习实验指导书有关部分,认真做好实验内容的准备,就实验可能出现的情况提前作出思考和分析。

(2)仔细观察调试程序过程中出现的各种问题,记录主要问题,作出必要说明和分析。

(3)遵守机房纪律,服从辅导教师指挥,爱护实验设备。

(4)实验课程不迟到,如有事不能出席,所缺实验一般不补。

(5)本实验采用的开发环境为Eclipse,同学在做实验之前要求熟悉该集成开发环境。

Experiment1ImplementingtheGourmetCoffeeSystem(4Hours)

Prerequisites,Goals,andOutcomes

Prerequisites:

Beforeyoubeginthisexercise,youneedmasteryofthefollowing:

∙ObjectOrientedProgramming

oKnowledgeofclassdesign

▪Classattributes

▪Constructors

▪Accessormethods

▪Mutatormethods

oKnowledgeofinheritance

▪Howtoimplementaspecialization/generalizationrelationshipusinginheritance

Goals:

ReinforceyourabilitytoimplementJavaclassesusinginheritance.

Outcomes:

Youwilldemonstratemasteryofthefollowing:

∙Implementingtheconstructors,accessors,andmutatorsofaJavaclass

∙Usinginheritancetoimplementaspecialization/generalizationrelationship

Background

ThisassignmentasksyoutoimplementsomeoftheclassesintheGourmetCoffeeSystemspecifiedonExercise2.

Description

Inthisassessment,youwillimplementtheclassesandrelationshipsillustratedinthefollowingclassdiagram:

Figure1PortionofGourmetCoffeeSystemclassdiagram

Theclassspecificationsareasfollows:

ClassProduct

TheclassProductmodelsagenericproductinthestore.

Instancevariables:

∙code.Theuniquecodethatidentifiestheproduct

∙description.Ashortdescriptionoftheproduct

∙price.Thepriceoftheproduct

Constructorandmethods:

∙publicProduct(StringinitialCode,

∙StringinitialDescription,

∙doubleinitialPrice)

Constructorthatinitializestheinstancevariablescode,description,andprice.

∙publicStringgetCode().Returnsthevalueofinstancevariablecode.

∙publicStringgetDescription().Returnsthevalueofinstancevariabledescription.

∙publicdoublegetPrice().Returnsthevalueofinstancevariableprice.

∙booleanequals(Objectobject).OverridesthemethodequalsintheclassObject.TwoProductobjectsareequaliftheircodesareequal.

∙StringtoString().OverridesthemethodtoStringintheclassObject.ReturnsthestringrepresentationofaProductobject.TheStringreturnedhasthefollowingformat:

code_description_price

Thefieldsareseparatedbyanunderscore(_).Youcanassumethatthefieldsthemselvesdonotcontainanyunderscores.

ClassCoffee

TheclassCoffeemodelsacoffeeproduct.ItextendsclassProduct.

Instancevariables:

∙origin.Theoriginofthecoffee

∙roast.Theroastofthecoffee

∙flavor.Theflavorofthecoffee

∙aroma.Thearomaofthecoffee

∙acidity.Theacidityofthecoffee

∙body.Thebodyofthecoffee

Constructorandmethods:

∙publicCoffee(StringinitialCode,

∙StringinitialDescription,

∙doubleinitialPrice,

∙StringinitialOrigin,

∙StringinitialRoast,

∙StringinitialFlavor,

∙StringinitialAroma,

∙StringinitialAcidity,

∙StringinitialBody)

Constructorthatinitializestheinstancevariablescode,description,price,origin,roast,flavor,aroma,acidity,andbody.

∙publicStringgetOrigin().Returnsthevalueofinstancevariableorigin.

∙publicStringgetRoast().Returnsthevalueofinstancevariableroast.

∙publicStringgetFlavor().Returnsthevalueofinstancevariableflavor.

∙publicStringgetAroma().Returnsthevalueofinstancevariablearoma.

∙publicStringgetAcidity().Returnsthevalueofinstancevariableacidity.

∙publicStringgetBody().Returnsthevalueofinstancevariablebody.

∙StringtoString().OverridesthemethodtoStringintheclassObject.ReturnsthestringrepresentationofaCoffeeobject.TheStringreturnedhasthefollowingformat:

code_description_price_origin_roast_flavor_aroma_acidity_body

Thefieldsareseparatedbyanunderscore(_).Youcanassumethatthefieldsthemselvesdonotcontainanyunderscores.

ClassCoffeeBrewer

ClassCoffeeBrewermodelsacoffeebrewer.ItextendsclassProduct.

Instancevariables:

∙model.Themodelofthecoffeebrewer

∙waterSupply.Thewatersupply(Pour-overorAutomatic)

∙numberOfCups.Thecapacityofthecoffeebrewer

Constructorandmethods:

∙publicCoffeeBrewer(StringinitialCode,

∙StringinitialDescription,

∙doubleinitialPrice,

∙StringinitialModel,

∙StringinitialWaterSupply,

∙intinitialNumberOfCups)

Constructorthatinitializestheinstancevariablescode,description,price,model,waterSupply,andnumberOfCups.

∙publicStringgetModel().Returnsthevalueofinstancevariablemodel.

∙publicStringgetWaterSupply().ReturnsthevalueofinstancevariablewaterSupply.

∙publicintgetNumberOfCups().ReturnsthevalueofinstancevariablenumberOfCups.

∙StringtoString().OverridesthemethodtoStringintheclassObject.ReturnsthestringrepresentationofaCoffeeBrewerobject.TheStringreturnedhasthefollowingformat:

code_description_price_model_waterSupply_numberOfCups

Thefieldsareseparatedbyanunderscore(_).Youcanassumethatthefieldsthemselvesdonotcontainanyunderscores.

ClassOrderItem

ClassOrderItemmodelsaniteminanorder.

Instancevariables:

∙product.Thisinstancevariablerepresentstheone-wayassociationbetweenOrderItemandProduct.ItcontainsareferencetoaProductobject.

∙quantity.Thequantityoftheproductintheorder.

Constructorandmethods:

∙publicOrderItem(ProductinitialProduct,

∙intinitialQuantity)

Constructorthatinitializestheinstancevariablesproductandquantity.

∙publicProductgetProduct().Returnsthevalueoftheinstancevariableproduct,areferencetoaProductobject.

∙publicintgetQuantity().Returnsthevalueoftheinstancevariablequantity.

∙publicvoidsetQuantity(intnewQuantity).SetstheinstancevariablequantitytothevalueofparameternewQuantity.

∙publicdoublegetValue().Returnstheproductofquantityandprice.

∙StringtoString().OverridesthemethodtoStringintheclassObject.ReturnsthestringrepresentationofanOrderItemobject.TheStringrepresentationhasthefollowingformat:

quantityproduct-codeproduct-price

Thefieldsareseparatedbyaspace.Youcanassumethatthefieldsthemselvesdonotcontainanyspaces.

Testdriverclasses

Completeimplementationsofthefollowingtestdriversareprovidedinthestudentarchive.Usethesetestdriverstoverifythatyourcodeworkscorrectly.

∙ClassTestProduct

∙ClassTestCoffee

∙ClassTestCoffeeBrewer

∙ClassTestOrderItem

Files

Thefollowingfilesareneededtocompletethisassignment:

∙student-files.zip—Downloadthisfile.Thisarchivecontainsthefollowing:

oTestProduct.java

oTestCoffee.java

oTestCoffeeBrewer.java

oTestOrderItem.java

Tasks

ImplementclassesProduct,Coffee,CoffeeBrewer,andOrderItem.DocumentusingJavadocandfollowSun'scodeconventions.Thefollowingstepswillguideyouthroughthisassignment.Workincrementallyandtesteachincrement.Saveoften.

1.Extractthefilesbyissuingthefollowingcommandatthecommandprompt:

C:

\>unzipstudent-files.zip

2.Then,implementclassProductfromscratch.UseTestProductdrivertotestyourimplementation.

3.Next,implementclassCoffeefromscratch.UseTestCoffeedrivertotestyourimplementation.

4.Then,implementclassCoffeeBrewerfromscratch.UseTestCoffeeBrewerdrivertotestyourimplementation.

5.Finally,implementclassOrderItemfromscratch.UseTestOrderItemdrivertotestyourimplementation.

Submission

Uponcompletion,submitonlythefollowing:

1.Product.java

2.Coffee.java

3.CoffeeBrewer.java

4.OrderItem.java

Experiment2ImplementingtheCollectionsintheGourmetCoffeeSystem(4Hours)

Prerequisites,Goals,andOutcomes

Prerequisites:

Beforeyoubeginthisexercise,youneedmasteryofthefollowing:

∙Collections

oUseofclassArrayList

oUseofiterators

Goals:

Reinforceyourabilitytoimplementclassesthatusecollections

Outcomes:

Youwilldemonstratemasteryofthefollowing:

∙ImplementingaJavaclassthatusescollections

Background

Inthisassignment,youwillimplementtheclassesintheGourmetCoffeeSystemthatusecollections.

Description

ThefollowingclassdiagramoftheGourmetCoffeeSystemhighlightstheclassesthatusecollections:

Figure2GourmetCoffeeSystemclassdiagram

Completeimplementationsofthefollowingclassesareprovidedinthestudentarchive:

∙Coffee

∙CoffeeBrewer

∙Product

∙OrderItem

∙GourmetCoffee

Inthisassignment,youwillimplementthefollowingclasses:

∙Catalog

∙Order

∙Sales

∙GourmetCoffee

Theclassspecificationsareasfollows:

ClassCatalog

TheclassCatalogmodelsaproductcatalog.ThisclassimplementstheinterfaceIterabletobeingabletoiteratethroughtheproductsusingthefor-eachloop.

Instancevariables:

∙products—AnArrayListcollectionthatcontainsreferencestoinstancesofclassProduct.

Constructorandpublicmethods:

∙publicCatalog()—Createsthecollectionproducts,whichisinitiallyempty.

∙publicvoidaddProduct(Productproduct)—Addsthespecifie

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2