免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
云南大学软件学院实 验 报 告姓名: 定欢 学号: 20141120188 班级: 日期: 2016年10月20日 成绩: JAVA实验五一、 实验目的:Applying OO Concepts Using Java二、 实验要求:Create a class called Circle.java with fields named radius(半径), area(面积), and diameter(直径). Include methods named setRadius(), getRadius(), and computeDiameter(), which calculates the circles diameter, and computeArea(), which computes the circles area. Hint: diameter of a circle is twice its radius. Hint: area of a circle is 3.14 multiplied by the square of the radius. Create a class called TestCircle. java whose main method declares 2 Circle objects. Using setRadius() method, assign one Circle a small radius value and assign another a larger radius value. Call computeDiameter() and computeArea for each circle and display the results. Output result of using command input 5 8: The area of a is 78.5The diameter of a is 10.0The area of b is 200.96The diameter of b is 16.0三、 实验内容:1、Circle.java2、CircleTest.java3、结果附加题:1.Monkey.java1. import java.util.Random;2. import java.util.Scanner;3.4. class Monkey 5. private String name;6. private double weight;7. private int age;8. private static String hab = 吃香蕉;9. public void setName(String name)10. = name;11. 12. 13. public void setWeight(double weight)14. this.weight = weight;15. 16. 17. public void setAge(int age)18. this.age = age;19. 20. 21. public String getName()22. return name;23. 24. 25. public double getWeight()26. return weight;27. 28. 29. public int getAge()30. return age;31. 32. /默认构造方法33. public Monkey()34. 35. 36. 37. /带参数构造方法38. public Monkey(String name, double weight, int age)39. = name;40. this.weight = weight;41. this.age = age;42. 43. 44. public void climbTree()45. Random r = new Random();46. int high = r.nextInt(60)+40;47. int banana = r.nextInt(54);48. System.out.println(name +会爬树+能爬+high);49. 50. if(high=60)51. System.out.println(name+会爬树,+能爬+high+,+摘到+banana+香蕉);52. System.out.println(剩下+(BananaTree.BanaSum-banana)+香蕉);53. 54. 55. else56. System.out.println(不能摘到香蕉);57. 58. 59. 60. 2.BananaTree:public class BananaTree double treeHigh;static double BanaSum;public void settreeHigh(double treeHigh)this.treeHigh = treeHigh;public void setBanaSum(double BanaSum)this.BanaSum = BanaSum;public double treeHigh()return treeHigh;public double getBanaSum()return BanaSum;public BananaTree()public BananaTree(double treeHigh,double BanaSum)this.treeHigh = treeHigh;this.BanaSum = BanaSum;3.MonkeyTest.javapublic class MonkeyTest public static void main(String args) / TODO Auto-generated method stubMonkey monkey1 = new Monkey();monkey1.setName(甲);monkey1.setAge(3);monkey1.setWeight(40);Monkey monkey2 = new Monkey(乙, 43, 3);BananaTree bt = new BananaTree();bt.settreeHigh(86)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 物业用电安全协议书协议书
- 2025医疗设备采购招标合同范本
- 生活垃圾清理协议书
- 委托设计协议书
- 电子签章使用协议书
- voip都用了那些协议书
- 2025电影制作委托贷款合同模板
- 2025年短视频代运营服务协议
- 2025购销合同精简版
- 2025租赁合同未续签范文
- 病原微生物实验室活动风险评估报告
- 2023年北京市公考公务员《申论》历年真题试卷试题及答案解析
- 普通高中英语课程标准词汇表
- 消毒供应中心进修总结汇报
- 城市韧性概念的国内外研究进展
- 河北邯郸2025年公开招聘农村(村务)工作者笔试题带答案分析
- 手外伤急诊处理原则
- 2025年深圳市盐田区(中小学、幼儿园)教师招聘考试模拟试题及答案解析
- 国际压力性损伤-溃疡预防和治疗临床指南(2025年版)解读
- 幕墙预埋件施工合同
- 2025年银联商务面试题及答案
评论
0/150
提交评论