




已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
浙江大学城市学院实验报告课程名称 面向对象程序设计 实验项目名称 实验13 Abstract class and interface (II) 学生姓名 专业班级 学号 注意:l 务请保存好各自的源代码,已备后用。l 完成本实验后,将实验项目文件和实验报告,压缩为rar文件,上传BB平台。l 文件名为:学号_姓名_日期_实验XX,如30801001_张三_20100305_实验01.rarl 请务必在下次实验课之前提交作业,BB平台设有截止日期,如果没有及时提交,将不能再提交。请勿抄袭作业。一次作业抄袭的扣分数至少为缺交作业的3倍。一. 实验目的和要求 1. 掌握抽象类的概念和使用2. 掌握接口的概念和使用3、掌握包装类的使用4、掌握BigInteger和BigDecimal类二. 实验内容 1. 问答题2. 问答题3. 问答题4. 问答题5. 编程题6. 编程题7. 编程题三. 实验结果与分析(可将程序运行结果截屏,也可分析运行结果)1、Show the printout of the following code:java.util.Date date = new java.util.Date();java.util.Date date1 = date;java.util.Date date2 = (java.util.Date)(date.clone();System.out.println(date = date1);System.out.println(date = date2);System.out.println(date.equals(date2);2、Show the printout of the following code:java.util.ArrayList list = new java.util.ArrayList();list.add(New York);java.util.ArrayList list1 = list;java.util.ArrayList list2 = (java.util.ArrayList)(list.clone();list.add(Atlanta);System.out.println(list = list1);System.out.println(list = list2);System.out.println(list is + list);System.out.println(list1 is + list1);System.out.println(list2.get(0) is + list2.get(0);System.out.println(list2.size() is + list2.size();3、What is wrong in the following code? (设GeometricObject和Circle类已有,修改这两个类,使得下面代码正确)public class Test public static void main(String args) GeometricObject x = new Circle(3);GeometricObject y = x.clone();System.out.println(x = y);4、Can each of the following statements be compiled?Integer i = new Integer(23);Integer i = new Integer(23);Integer i = Integer.valueOf(23);Integer i = Integer.parseInt(23, 8);Double d = new Double();Double d = Double.valueOf(23.45);int i = (Integer.valueOf(23).intValue();double d = (Double.valueOf(23.4).doubleValue();int i = (Double.valueOf(23.4).intValue();String s = (Double.valueOf(23.4).toString();5、Why do the following two lines of code compile but cause a runtime error?Number numberRef = new Integer(0);Double doubleRef = (Double)numberRef;因为Integer和Double不是基本数据类型。强制转换只能转换包含继承关系的类或基本类型数据。int numberRef =0;double doubleRef = (double)numberRef;或者Number numberRef = new Integer(0);Double doubleRef = new Double(numberRValue();都可以。6、Why do the following two lines of code compile but cause a runtime error?Number numberArray = new Integer2;numberArray0 = new Double(1.5);因为整数数组里不能放入非整数;Number numberArray = new Integer2;numberArray0 = new Double(1.5).intValue();这样可以。7、What is wrong in the following code?public class Test public static void main(String args) Number x = new Integer(3);System.out.println(Value();System.out.println(pareTo(new Integer(4);The method compareTo(Integer) is undefined for the type Number8、What is wrong in the following code?public class Test public static void main(String args) Number x = new Integer(3);System.out.println(Value();System.out.println(Integer)pareTo(new Integer(4);The method compareTo(Integer) is undefined for the type Number9、What is the output of the following code?public class Test public static void main(String args) System.out.println(Integer.parseInt(10);System.out.println(Integer.parseInt(10, 10);System.out.println(Integer.parseInt(10, 16);System.out.println(Integer.parseInt(11);System.out.println(Integer.parseInt(11, 10);System.out.println(Integer.parseInt(11, 16);10、(Revising the House class) Rewrite the House class in Listing 14.9 to perform adeep copy on the whenBuilt field. /* Override the protected clone method defined in the Object class, and strengthen its accessibility */ public Object clone() Object o=null; try o=super.clone(); catch(CloneNotSupportedException e) System.out.println(e.toString(); return o; 11、(Enabling Circle comparable) Rewrite the Circle class in Listing 14.2 to extendGeometricObject and implement the Comparable interface. Override theequals method in the Object class. Two Circle objects are equal if their radii are the same. Draw the UML diagram that involves Circle, GeometricObject, and Comparable.public class Circle extends GeometricObject implements Comparable private double radius; public Circle() public Circle(double radius) this.radius = radius; /* Return radius */ public double getRadius() return radius; /* Set a new radius */ public void setRadius(double radius) this.radius = radius; /* Return area */ public double getArea() return radius * radius * Math.PI; /* Return diameter */ public double getDiameter() return 2 * radius; /* Return perimeter */ public double getPerimeter() return 2 * radius * Math.PI; /* Print the circle info */ public void printCircle() System.out.println(The circle is created + getDateCreated() + and the radius is + radius); public int equals(Circle o) if(this.radius=o.radius) return 1; else return 0; public int compareTo(Circle o) if (this.equals(o)=1) return 1; else return 0; 12、(Enabling Rectangle comparable) Rewrite the Rectangle class in Listing 14.3 to extend GeometricObject and implement the Comparable interface. Override the equals method in the Object class. Two Rectangle objects are equal if their areas are the same. Draw the UML diagram that involves Rectangle, GeometricObject, and Comparable.public class Rectangle extends GeometricObject implements Comparable private double width; private double height; public Rectangle() public Rectangle(double width, double height) this.width = width; this.height = height; /* Return width */ public double getWidth() return width; /* Set a new width */ public void setWidth(double width) this.width = width; /* Return height */ public double getHeight() return height; /* Set a new height */ public void setHeight(double height) this.height = height; /* Return area */ public double getArea() return width * height; /* Return perimeter */ public double getPerimeter() return 2 * (width + height); public int equals(Rectangle o) if(this.getArea()=o.getArea() return 1; else return 0; public int compareTo(Rectangle o) if (this.equals(o)=1) return 1; else return 0; 13、 (The Octagon class) Write a class named Octagonthat extends GeometricObjectand implements the Comparable and Cloneable interfaces. Assume that all eight sides of the octagon are of equal size. The area can be computed using the following formula:Draw the UML diagram that involves Octagon, GeometricObject, Comparable, and Cloneable. Write a test program that creates an Octagon object
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 肾内科医生外出进修汇报
- 消防基本常识与公共基础知识题库(含答案)
- 2025年事业单位工勤技能-海南-海南水土保持工三级(高级工)历年参考题库含答案解析
- 2025-2030中国糖蜜行业供需态势及消费趋势预测报告
- 2025年事业单位工勤技能-浙江-浙江医技工三级(高级工)历年参考题库含答案解析(5套)
- 2025年事业单位工勤技能-河南-河南防疫员三级(高级工)历年参考题库含答案解析
- 2025年事业单位工勤技能-河南-河南管道工一级(高级技师)历年参考题库含答案解析
- 2025年事业单位工勤技能-河南-河南林木种苗工三级(高级工)历年参考题库含答案解析
- 2025年事业单位工勤技能-河北-河北防疫员五级(初级工)历年参考题库含答案解析
- 2025年事业单位工勤技能-江西-江西环境监测工四级(中级工)历年参考题库含答案解析(5套)
- 2024年工会财务知识竞赛试题及答案
- 26个英语字母描红练习(素材)-小学英语
- DL∕T 686-2018 电力网电能损耗计算导则
- 糖尿病医疗广告宣传指南
- 2023年河南省中考数学试卷及答案
- 中外民歌欣赏(高中音乐课件)
- Revit-基础教程课件
- 大学美育(第二版) 课件 第五单元:书法艺术
- 消防工程技术咨询合同
- 从《史记》看司马迁的命运观
- 高中新外研版单词总表(必修123+选修1234)
评论
0/150
提交评论