面向对象编程的练习

面向对象编程的练习

ID:42037989

大小:76.50 KB

页数:4页

时间:2019-09-06

面向对象编程的练习_第1页
面向对象编程的练习_第2页
面向对象编程的练习_第3页
面向对象编程的练习_第4页
资源描述:

《面向对象编程的练习》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、实验报告(二)院(系)数学与统计学院课程名称:Java程序设计日期:2014年10月31日班级学号实验室专业姓名计算机号实验名称面向对象编程的练习成绩评定所用软件NetBeans指导教师实验目的(1)掌握类的声明、对象的创建。(2)掌握如何使用类来实现现实中具体的模拟。实验内容(1)Book类的定义与对彖的实例化(2)定义一个人类,有姓名、年龄两个属性。在定义一个学生类用于继承人类,学生类除了继承人类的属性外,还有学生学号、姓名、班级、所学课程等属性,并且实现学习的行为。在定义一个测试类,用于测试学生类。(3)编写一个Java应用程序,该程序中有3个类:Trangle、Ladder和C

2、ircle,分别用来刻iffll"二角形”、“梯形”和“圆形”。至少要实现如下基木要求:a)Trangle类具有类型为double的三个边,以及周长、面积属性,Trangle类具有返回周长、而积以及修改三个边的功能。另外,Trangle类还具有一个boolean型的属性,该屈性用來判断三个属能否构成一个三角形。b)Ladder类具冇类型double的上底、下底、高、面积属性,具冇返回面积的功能。c)Circle类具有类型为double的半径、周长和面积属性,具有返回周长、面枳的功能。实验过程1.classBook{Stringname,author,publishinghouse,pr

3、ices;StringgetnamcO{returnname;}voidsetname(Stringnaroc){this・namc=namc;}Stringgetauthor(){returnauthor;}voidsetauthor(Stringauthor){this.author=author;}StringgetpublishinghouseO{returnpublishinghouse:}voidsetpubIishinghouse(Stringpublishinghouse){this・publishinghouse=publishinghouse;}Stringgetp

4、rices(){returnprices;}voidsetprices(Stringprices){this・prices=prices;}publicstaticvoidmain(String[]args){BookBookl=newBook0:BookBook2=newBook();Bookl.setname(^7^等代数");Bookl.setauthor("帐明”);Bookl.setpub1ishinghouseC北京出版社");Bookl・setpi'ices("25元");Book2.setname数学分析");Book2.setauthorC*李红");Book2・se

5、tpub1ishinghouseC北京出版社");Book2.setprices("30元"):System.out.int("lhefirstBookname:^);System・out.p^intin(Bookl・getnamo());System.out.print(""thefirstBookauthor/):System・out.p^intin(Bookl・getauthor());System.out.pTint(,zthefirstBookpub1ishinghouse:/z):System.out・printIn(Book1.getpublishinghouse());

6、System.out.pTint(^thefirstBookprices:^);System・out.p^intin(Bookl・getpricesO);System.out.print(/zthesecondBookname:*);System・out.p^intIn(Book2・getnamo());System.out.printC'thesecondBookauthor/):System.out・printIn(Book2・getauthor());System.out.print(/zthesecondtBookpublishinghouse:;System.out・prin

7、tIn(Book2・getpublishinghouse());System.out.print(/zthesecondBookprices/);System.out・printIn(Book2・getpricesO);}}run:thefirstBookname:高等代数thefirstBookauthor:明thefirstBookpublishinghous己:北京出版社thefirstBookprices:25tlthesecondBo

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。