JAVA实验指导书实验一.docx
- 文档编号:16647268
- 上传时间:2023-07-16
- 格式:DOCX
- 页数:11
- 大小:36.60KB
JAVA实验指导书实验一.docx
《JAVA实验指导书实验一.docx》由会员分享,可在线阅读,更多相关《JAVA实验指导书实验一.docx(11页珍藏版)》请在冰点文库上搜索。
JAVA实验指导书实验一
《JavaSE程序设计》
实验指导手册
授课教师:
崔毅东
实验指导教师:
崔毅东
教学对象:
二年级本科生
开课时间:
秋季学期
北京邮电大学软件学院
《Java语言与编程》实验指导书
程保中孙艺
一、实验一:
Java程序编制(基础练习)
1、实验目的
学生通过使用Java语言进行基本程序的开发,掌握Java通用IDE,练习类的封装使用、Java基本类库的使用、利用UML进行简单建模。
2、实验内容(详细内容见附件一)
3、实验环境
a)Windows
b)Eclipse或者NetBean
4、实验要求
1)独立完成实验内容要求
2)熟练使用Java常用IDE进行编程
3)需要上交源程序文件
4)需要打印实验报告上交(标准格式见附件二)
5、实验步骤
1)启动Java常用IDE。
2)建立project。
3)编辑源程序。
4)编译、链接并执行源程序,看结果是否正确。
5)如果报错或告警,做必要修改,重复3)--5)步骤直到没有错误和告警。
附件一:
Project#1AMathLearningTool(coversChapter2)
CSCI1301IntroductiontoProgramming
ArmstrongAtlanticStateUniversity
Developaprogramthatletsafirstgraderpracticeadditions.Theprogramrandomlygeneratestwosingle-digitintegersanddisplaysaquestionsuchas“Whatis7+9?
”tothestudent,asshowninFigurea.Afterthestudenttypestheanswerintheinputdialogbox,theprogramdisplaysamessagedialogboxtoindicatewhethertheansweristrueorfalse,asshowninFigureb.
(a)(b)(c)(d)
NOTE:
Writetheprogramwithoutusingconditionalstatements.UseonlythematerialsyoulearnedinChapter2.
(注:
写程序,无需使用条件语句。
只使用你在第2章所学的材料。
)
Hint:
GeneratetherandomnumberusingtheSystem.currentTimeMillis()introducedinChapter2.
提示:
使用系统生成的随机数。
currenttimemillis()介绍2章。
Submitthefollowingitems:
1.Analysis:
Restatetheprobleminyourownwords(e.g.,whatisinput,outputifany,whatneedstobecomputed,whatdataneedstobestoredandtheirtype).
1.分析:
用自己的话重述问题(例如,什么是输入,输出,如果有,需要计算,哪些数据需要存储和类型)。
2.Design:
ClearlydescribethestepstosolvethisproblemusingEnglishorpseudocode.
2.设计:
清晰地描述用英语或伪代码来解决这个问题的步骤。
3.Coding:
ImplementthesolutioninJava.
4.Testing:
Makesurethatthenumbersappearrandom.Submitthescreenshotsoftwosampleruns.
4.测试:
确保数字显示随机。
提交两个示例运行的屏幕截图。
Project#2TaxTable(coversChapter3)
CSCI1301IntroductiontoProgramming
ArmstrongAtlanticStateUniversity
TheUnitedStatesfederalpersonalincometaxiscalculatedbasedonfilingstatusandtaxableincome.Therearefourfilingstatuses:
singlefilers,marriedfilingjointly,marriedfilingseparately,andheadofhousehold.Thetaxratesfor2005areshowninTable(a)-(d).Ifyouare,say,singlewithataxableincomeof$10,000,thefirst$7,300istaxedat10%andtheother$2,700istaxedat15%.Soyourtaxis730+2700*0.15.
Schedule X—Single
Iftaxableincomeis over--
Butnotover--
Thetaxis:
$0
$7,300
730美元加15%的金额超过7300
10%oftheamountover$0
$7,300
$29,700
$730plus15%oftheamountover7,300
$29,700
$71,950
$4,090.00plus25%oftheamountover29,700
$71,950
$150,150
$14,652.50plus28%oftheamountover71,950
$150,150
$326,450
$36,548.50plus33%oftheamountover150,150
$326,450
nolimit
$94,727.50plus35%oftheamountover326,450
ScheduleY-1—MarriedFilingJointlyorQualifyingWidow(er)
Iftaxableincomeis over--
Butnotover--
Thetaxis:
$0
$14,600
10%oftheamountover$0
$14,600
$59,400
$1,460.00plus15%oftheamountover14,600
$59,400
$119,950
$8,180 plus25%oftheamountover59,400
$119,950
$182,800
$23,317.50 plus28%oftheamountover119,950
$182,800
$326,450
$40,915.50plus33%oftheamountover182,800
$326,450
nolimit
$88,320.00 plus35%oftheamountover326,450
ScheduleY-2—MarriedFilingSeparately
Iftaxableincomeis over--
Butnotover--
Thetaxis:
$0
$7,300
10%oftheamountover$0
$7,300
$29,700
$730plus15%oftheamountover7,300
$29,700
$59,975
$4,090 plus25%oftheamountover29,700
$59,975
$91,400
$11,658.75 plus28%oftheamountover59,975
$91,400
$163,225
$20,457.75plus33%oftheamountover91,400
$163,225
nolimit
$44,160.00 plus35%oftheamountover163,225
Schedule Z—HeadofHousehold
Iftaxableincomeis over--
Butnotover--
Thetaxis:
$0
$10,450
10%oftheamountover$0
$10,450
$39,800
$1,045plus15%oftheamountover10,450
$39,800
$102,800
$5,447.50 plus25%oftheamountover39,800
$102,800
$166,450
$21,197.50 plus28%oftheamountover102,800
$166,450
$326,450
$39,019.50plus33%oftheamountover166,450
$326,450
nolimit
$91,819.50 plus35%oftheamountover326,450
Developaprogramthatprintsataxtablefortaxableincomefrom$50,000to$60,000withintervalsof$50forallfourstatuses,asfollows:
写一个计程序,打印应纳税所得税表从50000美元到60000美元的所有四个状态的50个区间
taxableSingleMarriedMarriedHeadof
IncomeJointSeparateaHouse
5000098467296103988506
5005098597309104118519...
599501253299821319011192600001254699961320511206
NOTE:
thenumbersintheprecedingtaxtableareincorrectintentionally.Youshouldprintthecorrectvaluesinthetable.
Submitthefollowingitems:
1.Analysis:
Restatetheprobleminyourownwords(e.g.,whatisinput,outputifany,whatneedstobecomputed,whatdataneedstobestoredandtheirtype).
2.Design:
ClearlydescribethestepstosolvethisproblemusingEnglishorpseudocode.
3.Coding:
ImplementthesolutioninJava.
4.Testing:
Submitthescreenshotsforfirst20linesinthetaxtable.
4.测试:
在税收表中提交前20行的屏幕截图。
Project#3LeastCommonMultiple(coversChapter5)
CSCI1301IntroductiontoProgramming
ArmstrongAtlanticStateUniversity
Definition:
Theleastcommonmultiple(LCM)oftwonumbersisthesmallestnumberthatisamultipleofboth.Forexample,theLCMfor8and12is24,for15and25is75,andfor120and150is600.
Developaprogramthatpromptstheusertoentertwointegersandfindstheirleastcommonmultiple.
开发一个程序,提示用户输入两个整数,并找到它们的最小公倍数。
TofindtheLCMoftwonumbers,firstcreateaprimefactortableforeachnumber.Thefirstcolumnofthetableconsistsofalltheprimefactorsandthesecondcolumntrackstheoccurrenceofthecorrespondingprimefactorinthenumber.Forexample,theprimefactorsfor120are2,2,2,3,5,sotheprimefactortablefornumber120isshownasfollows:
Theprimefactorsfor150are2,3,5,5,sotheprimefactortablefornumber150isshown
asfollows:
TheLCMofthetwonumbersconsistsofthefactorswiththelargestoccurrenceinthetwonumbers.SotheLCMfor120and150is
where2appearsthreetimesin120,3onetimein120,and5twotimesin150.
Submitthefollowingitems:
1.Analysis:
Restatetheprobleminyourownwords(e.g.,whatisinput,outputifany,whatneedstobecomputed,whatdataneedstobestoredandtheirtype).
2.Design:
ClearlydescribethestepstosolvethisproblemusingEnglishorpseudocode.(Hint:
Theprimefactortablecanberepresentedusingatwo-dimensionalarray.WriteamethodnamedgetPrimeFactors(intnumber)thatreturnsatwo-dimensionalarrayfortheprimefactortable.)
(提示:
可以使用一个二维数组表示素因子表。
写一个方法叫getprimefactOR(int数),返回的素因子表的二维数组。
)
3.Coding:
ImplementthesolutioninJava.
4.Testing:
TestyourprogramtofindtheLCMfor(120,150),(7,14),(7,8),(1,2),and(345,455)
Project#4DesignClasses(coversChapter6)
CSCI1302IntroductiontoProgramming
ArmstrongAtlanticStateUniversity
Thisprojectconsistsoftwoseparateproblems.
1.DesignaclassnamedRectangletorepresentarectangle.Theclasscontains:
∙Twodoubledatafieldsnamedwidthandheightthatspecifythewidthandheightoftherectangle.Thedefaultvaluesare1forbothwidthandheight.
∙Astringdatafieldnamedcolorthatspecifiesthecolorofarectangle.Hypothetically,assumethatallrectangleshavethesamecolor.Thedefaultcoloriswhite.
∙Ano-argconstructorthatcreatesadefaultrectangle.
没有参数的构造函数,创建一个默认的矩形。
∙Aconstructorthatcreatesarectanglewiththespecifiedwidthandheight.
创建一个具有指定宽度和高度的矩形的构造函数
∙Theaccessorandmutatormethodsforallthreedatafields.
所有三个数据字段的访问器方法。
∙AmethodnamedgetArea()thatreturnstheareaofthisrectangle.
一种getarea()返回这个矩形的面积。
∙AmethodnamedgetPerimeter()thatreturnstheperimeter.
一种getperimeter()返回周长。
DrawtheUMLdiagramfortheclass.Implementtheclass.
这类画UML图。
实现类。
WriteatestprogramthatcreatestwoRectangleobjects.Assignwidth4andheight40tothefirstobjectandwidth3.5andheight35.9tothesecondobject.AssigncolorredtoallRectangleobjects.Displaythepropertiesofbothobjectsandfindtheirareasandperimeters.
编写一个创建两个矩形对象的测试程序。
分配宽度4和高度40到第一个对象和宽度3.5和高度35.9到第二个对象。
将颜色分配给所有矩形对象。
显示的对象的属性,找到他们的周长和面积。
2.DesignaclassnamedTime.Theclasscontains:
∙Datafieldshour,minute,andsecondthatrepresentsatime.
∙Ano-argconstructorthatcreatesaTimeobjectforthecurrenttime.(Thedatafieldsvaluewillrepresentthecurrenttime)
在没有参数的构造函数中创建时间为当前时间对象.(数据值将代表当前时间)
∙AconstructorthatconstructsaTimeobjectwithaspecifiedelapsetimesincethemiddlenight,Jan1,1970inmilliseconds.(Thedatafieldsvaluewillrepresentthistime)
一个构造函数构造一个时间与指定的时间从半夜对象,1970年1月1日在毫秒。
(数据字段值将代表这段时间)
∙Threegetmethodsforthedatafieldshour,minute,andsecond,respectively.
DrawtheUMLdiagramfortheclass.Implementtheclass.WriteatestprogramthatcreatestwoTimeobjects(usingnewTime()andnewTime(555550000))anddisplaytheirhour,minute,andsecond.
这类画UML图。
实现类。
写一个测试程序,创建两个时间对象(使用新的time()和
新时期(555550000)),显示小时,分钟和秒。
Hint:
ThecurrenttimecanbeobtainedusingSystem.currentTime(),asshowninListing2.8,ShowCurrentTime.java.Theotherconstructorsetsthehour,minute,andsecondforthespecifiedelapsetime.Forexample,iftheelapsetimeis555550000milliseconds,thehouris10,theminuteis19,andthesecondis10.
提示:
当前时间可以通过使用System.currenttime(),如Listing2.8所示,ShowCurrentTime.java。
其他构造函数设置小时,分钟和第二的指定时间。
例如,如果过去的时间是55555的0000毫秒,时间是10分钟,这是19,第二是10。
附件二:
北京邮电大学软件学院
实验报告
课程名称:
JavaSE程序设计
项目名称:
Java编程(基础练习)
项目完成人:
姓名:
________学号:
________
姓名:
________学号:
________
姓名:
________学号:
___
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- JAVA 实验 指导书