没有合适的资源?快使用搜索试试~ 我知道了~
首页利用java定义Point2D及定义接口与抽象类
1、定义Point2D,及定义它的属性和方法; 2、定义抽象类Shape,抽象方法为showArea(),再定义矩形类Rectangle,正方形类Square,圆类 Circle,和各自的属性。定义主类、主方法,在main方法中构造3个对象,调用showArea方法;定义接口DiagArea,其中包含方法double getDiagonal(),在主main方法中输出方法执行结果。
资源详情
资源评论
资源推荐
1.(第 1 题)定义 Point2D,及定义它的属
性和方法;
class Point2D
{
public int x;
public int y;
public void Point2D(int i,int j)
{
x=i;
y=j;
}
public void offset(int a, int b)
{
x=x+a;
y=y+b;
}
public void show()
{
System.out.println("("+x+","+y+")");
}
}
public class Point3D extends Point2D
{
public int z;
public void Point3D(Point2D p,int m)
{
x=p.x;
y=p.y;
z=m;}
public void offset(int a, int b,int c)
{ x=x+a;
y=y+b;
z=z+c;}
public void show2()
{System.out.println("("+x+","+y+","+z+")");}
public static void main(String[] args)
{
Point2D p2d1=new Point2D();
Point2D p2d2=new Point2D();
p2d1.Point2D(2,3);
System.out.println("A 点二维坐标:");
p2d1.show();
p2d2.Point2D(3,4);
System.out.println("B 点二维坐标:");
p2d2.show();
double a,b,c;
a=p2d1.x-p2d2.x;
a=a*a;
b=p2d1.y-p2d2.y;
b=b*b;
c=a+b;
c=Math.sqrt(c);
System.out.println("两点二维坐标间的
距离:"+c);
Point3D p3d1=new Point3D();
Point3D p3d2=new Point3D();
p3d1.Point3D(p2d1,4);
System.out.println("A 点三维坐标:");
p3d1.show2();
p3d2.Point3D(p2d2,5);
System.out.println("B 点三维坐标:");
p3d2.show2();
a=p3d1.x-p3d2.x;
a=a*a;
b=p3d1.y-p3d2.y;
b=b*b;
c=p3d1.z-p3d2.z;
c=c*c;
c=a+b+c;
c=Math.sqrt(c);
System.out.println("两点三维坐标间的
距离:"+c);
}
}
2.(第 2 题)定义抽象类 Shape,抽象方法
为 showArea() , 再 定 义 矩 形 类
Rectangle, 正 方 形 类 Square, 圆 类
Circle,和各自的属性。定义主类、主方
法,在 main 方法中构造 3 个对象,调用
showArea 方法;定义接口 DiagArea,
其中 包含 方法 double getDiagonal() ,
Sakurayun
- 粉丝: 3
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0