




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 35595-2025玻璃容器砷、锑溶出量的测定方法
- 2025喀什地区两级法院机关招聘聘用制书记员(43人)模拟试卷及参考答案详解一套
- 2025湖南株洲市石峰区公益性岗位上半年(第三批)招聘3人考前自测高频考点模拟试题附答案详解(考试直接用)
- 2025广西柳州市鱼峰公园管理处招聘编外人员4人考前自测高频考点模拟试题及1套完整答案详解
- 安全培训获奖感言课件
- 2025湖南怀化市溆浦县卫健局公开招聘乡镇卫生院编外专技人员20人模拟试卷及1套完整答案详解
- 2025年常州市武进区卫健系统公开招聘工作人员12人模拟试卷及一套答案详解
- 2025贵州玉林市北流市政协办公室招聘公益性岗位模拟试卷及答案详解(新)
- 2025广东中山市横栏镇纪检监察办公室招聘1人模拟试卷及答案详解(网校专用)
- 2025湖南邵阳市新宁产业开发区公开选调工作人员5人考前自测高频考点模拟试题及答案详解1套
- DB31/T 978-2016同步注浆用干混砂浆应用技术规范
- 教育新闻宣传工作培训
- 【DAMA】2025智变-AI赋能政府与央国企智能化转型白皮书
- 新教材部编版二年级上册《4.彩虹》教学设计
- 航空宠物知识培训课件
- 综合实践活动课程设计
- 2025年法官员额考试题及答案
- 备考2025年成人高考-专升本-政治考点及必背知识点大全
- TCECA-G 0330-2024 磁悬浮离心式鼓风机 技术条件
- (2025)新版十八项医疗核心制度
- 中考英语复习语法专项讲练06现在完成时含解析
评论
0/150
提交评论