下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、【问题描述】定义一个抽象基类Shape,它包含三个抽象方法center()、diameter()、getArea(),从Shape类派生出Square和Circle类,这两个类都用center()计算对象的中心坐标,diameter()计算对象周长,getArea()方法计算对象的面积。编写应用程序使用Rectangle类和Circle类。【输入形式】输入圆的中心坐标、半径;输入正方形中心、边长【输出形式】输出圆的中心坐标、圆周长、圆面积;输出正方形中心坐标、周长、面积【样例输入】【样例输出】please input the circle center:4 4 please input the
2、 circle radius:3 the circle center is (4, 4) the circle diameter is 18.84 the circle area is 28.26 please input thesquare center:5 5 please input the square radius:2the square center is (5,5) the square diameter is 8the square area is 4【样例说明】样例输出中横线是输入。【评分标准】一个测试样例import java.text.DecimalFormat;impo
3、rt java.util.Scanner;public class Test72 public static void main(String args) Scanner scan=new Scanner(System.in); int x,y,r; System.out.println(please input the circle center: ); x=scan.nextInt(); y=scan.nextInt(); System.out.println(please input the circle radius: ); r=scan.nextInt(); Circle circl
4、e = new Circle(r);double area = circle.getArea();double diameter = circle.diameter();System.out.println(the circle center is ( + x + , + y + );System.out.println(the circle diameter is + new DecimalFormat(0.00).format(diameter);System.out.println(the circle area is + new DecimalFormat(0.00).format(a
5、rea); System.out.println(please input the square center: ); x=scan.nextInt(); y=scan.nextInt(); System.out.println(please input the square side length: ); r=scan.nextInt();Rectangle rectangle = new Rectangle(r, r);area = rectangle.getArea();diameter = rectangle.diameter();System.out.println(the squa
6、re center is ( + x + , + y + );System.out.println(the square diameter is + new DecimalFormat(0).format(diameter);System.out.println(the square area is + new DecimalFormat(0).format(area);abstract class Shape public abstract double getArea();class Rectangle extends Shape private double width; private double height; public Rectangle(double width, double height) this.width = width; this.height = height; public double getArea() return width * height;public double diameter() return width + height + width + height; class Circle extends Shape private double r; public Circle(double radius)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 失智老年人照护员QC管理测试考核试卷含答案
- 汽车维修工班组评比竞赛考核试卷含答案
- 皮革护理师风险评估与管理竞赛考核试卷含答案
- 矿用电机车机械装配工岗前技术评优考核试卷含答案
- 电线电缆检验员保密意识竞赛考核试卷含答案
- 一到五的加法题目及答案
- 中班游乐园试讲题目及答案
- 龙华二模作文题目及答案
- 脊髓损伤康复考核试题及答案
- 2026年中建招聘测试题目及答案
- 细胞生物学课件9 细胞信号转导
- 西南大学PPT 01 蓝色版通用模板
- 市场监管公务员考核表个人总结5篇
- 辽宁某办公大楼室内装饰装修工程施工组织设计
- 车灯研发设计过程课件
- 部编版语文四年级下册全册教案
- 最新安全生产管理教材电子版
- TPM基础知识培训教材课件
- 石榴花开别样红籽籽同心一家亲民族团结一家亲主题班会课件
- 自考00402《学前教育史》重点归纳
- 通用规范汉字表注音完整版
评论
0/150
提交评论