JA实习报告and_第1页
JA实习报告and_第2页
JA实习报告and_第3页
JA实习报告and_第4页
免费预览已结束,剩余1页可下载查看

下载本文档

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

文档简介

1、信息工程学院1Java程序设计实习报告学院 :信息工程学院班级:姓名:学号:成绩:1实验目的掌握 Java 程序面向对象编程的基本架构,会运用面向对象的思想编写Java 程序。2. 实验过程熟悉 JAVA的编程环境实验题 1 阅读如下程序,完成思考题。classCCircledoublepi;doubleradius;doublegetRadius()raw();程序源代码如下:Shape类:publicclassshapevoiddraw()voiderase()publicshape()raw();程序运行结果如下:实验题 2 有两个类:MobileManagement和 Mobile,分

2、别描述如图所示两部手机名称及价格,类 MobileManagement在包中,而 Mobile 在包中。它们代码如下。运行,你应该看到如图所示结果。 基本要求 在空白处填写相关代码并修改上面程序,使程序能够显示两部手机的价格和数量,运行结果如图所示。E365,1780RMBM330,1450RMB图手机及价格图实验报告的内容与格式按任课教师的要求书写。图运行结果图程序源代码如下:. 下的 MobileManagement 类:packageimportpublicclassMobileManagement/*Definestheentrypointoftheapplication.*/publ

3、icstaticvoidmain(Stringargs)Mobilemobile1=newMobile("E365",1780);Mobilemobile2=newMobile("M330",1450);(null,"Mobilephones:nn"+()+"n"+();下的 Mobile 类:packagepublicclassMobile/*Holdsthenameofthemobile.*/privateStringname;/*Holdsthepriceofthemobile.*/privatefloatp

4、rice;/*Createsanewmobileobject.*/publicMobile(Stringname,floatprice)=name;=price;/*Getsthenameofthemobile.*/publicStringgetName()returnname;/*Getsthepriceofthemobile.*/publicfloatgetPrice()returnprice;运行结果如下:实验题 3 有四个类,主类 Store 在包中, Mobile 、Mp3Player、Product 在包 .data 中, Mobile 、Mp3Player 是 Product 的

5、子类 . 基本要求 设计类 Mobile 和类 MP3Player,使它们和类Product 、Store 组成一个完整的程序,且运行结果如图所示。程序源码如下:.data 中 Product 类:packagepublicabstractclassProuductimplementsComparable<Prouduct>/*Holdsthenameoftheproduct.*/protectedStringname;/*Holdsthepriceoftheproduct.*/protectedfloatprice;/*Holdsthenumberofproducts.*/pro

6、tectedstaticintcount;/*Createanewproductobject.*/protectedProuduct()/*Getsthenameoftheproduct.*/publicStringgetName()returnname;/*Getsthepriceoftheproduct.*/publicfloatgetPrice()returnprice;/*Getsthenumberofproducts.*/publicstaticintgetCount()returncount;/*Comparesthisproductwiththegivenproduct.*/pu

7、blicintcompareTo(Prouductproduct)returnnewFloat()pareTo(price);.data 中 Mp3Player 类:packagepublicclassMP3playerextendsProuductprivateStringname;privatefloatprice;privateintmemory;publicMP3player(Stringname,intmemory,floatprice)ata 中 Mobile 类:packagepublicclassMobileextendsProuductprivateStringname;pr

8、ivatefloatprice;privateStringWTO;publicMobile(StringWTO,Stringname,floatprice)/publicstaticvoidmain(Stringargs)Mobilemobile1=newMobile("ChinaMobile","E365",1780);Mobilemobile2=newMobile("ChinaMobile","M330",1450);MP3playerplayer1=newMP3player("MeizoX3&quo

9、t;,256,399);MP3playerplayer2=newMP3player("MeizoE5",512,580);MP3playerplayer3=newMP3player("XliveXMMP3Play",256,930);Prouductprouducts=mobile1,mobile2,player1,player2,player3;(prouducts);Stringtext=""for(intindex=0;index<+index)text+=prouductsindex.toString()+"n

10、"(null,"Theproductsare:nn"+text+"nThereare"+()+"products.");程序运行结果如下:实验题 4 用 LIST 存放对象。利用面向对象的思想,创建以下类:Person 类,包含 Person 的姓名和身份证号码。Student 类,首先是一个Person,除此之外,包含学生的语文、数学、英文课的成绩。Teacher 类,首先是一个Person,除此之外,包含教师的工资。请创建姓名张三身份证号的 Person 对象。请创建姓名李四身份证号语文: 89数学: 93英文: 94的 Student 对象。请创建姓名王五身份证号工资: 3000的 Teacher 对象。将这些对象存放在List中,并打印出 List中存放的内容。程序源代码如下:Person 类:publicclassPersonimplementsComparable<Person>Stringname;StringID;publicPerson();publicclassMAPpublicMAP()terator();习总结:通过这次实习让我懂得了很多java 的知识,更加加深了对java

温馨提示

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

评论

0/150

提交评论