导航:首页 > 编程语言 > java点类

java点类

发布时间:2023-06-05 21:31:21

java定义一个点类Point, 具备坐标系中的横坐标x, 和纵坐标y, 并实现如下功能:

Point类


publicclassPoint{
privatefloatx;
privatefloaty;
publicPoint(floatx,floaty){
this.x=x;
this.y=y;
}

publicfloatgetX(){
returnx;
}

publicvoidsetX(floatx){
this.x=x;
}

publicfloatgetY(){
returny;
}

publicvoidsetY(floaty){
this.y=y;
}

publicfloatdistanceToOrigin(){
return(float)Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2));
}

publicfloatdistanceToOther(intx,inty){
return(float)Math.sqrt(Math.pow(this.x-x,2)+Math.pow(this.y-y,2));
}

publicfloatdistanceToOther(Pointpoint){
return(float)Math.sqrt(Math.pow(this.x-point.x,2)+Math.pow(this.y-point.y,2));
}
}

测试类

publicclassTestPoint{
publicstaticvoidmain(String[]args){
Pointp1=newPoint(3,5);
Pointp2=newPoint(7,8);
System.out.println(p1.distanceToOrigin());
System.out.println(p2.distanceToOrigin());
System.out.println(p1.distanceToOther(20,30));
System.out.println(p2.distanceToOther(20,30));
System.out.println(p1.distanceToOther(p2));
}
}
阅读全文

与java点类相关的资料

热点内容
取小数位数php 浏览:715
mdk编译重复代码 浏览:100
容器怎么连接云服务器 浏览:846
程序员多久能提升 浏览:147
bpmx3源码 浏览:123
通信类单片机 浏览:817
加密植发的区别 浏览:538
程序员跑需求 浏览:224
s7服务器怎么设置 浏览:344
2k17连接不上服务器怎么办 浏览:494
人力资源系统开源源码 浏览:687
河北视频加密有哪些 浏览:651
桌面两个微信怎么都加密码 浏览:278
长沙单身程序员 浏览:886
服务器下载异常是因为什么 浏览:705
java防刷 浏览:844
3dmax取消当前命令 浏览:361
显示当前模式下所有可执行的命令 浏览:760
为什么程序员拿了股份还要高薪 浏览:949
电脑运行命令里的记录能删吗 浏览:699