导航:首页 > 编程语言 > 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点类相关的资料

热点内容
编程珠玑笔记 浏览:276
结束命令行 浏览:268
力学原理pdf 浏览:731
宏定义编译后不变 浏览:399
如何搞免费服务器 浏览:208
神经系统pdf 浏览:667
如何查看服务器上的数据库服务器 浏览:190
压缩机型号v代表什么 浏览:54
旅游类源码 浏览:864
电脑服务器类型怎么设置 浏览:232
pdf炒股 浏览:788
服务器地址缺少端口号什么意思 浏览:532
下载需要解压的小说用哪个软件 浏览:536
广东分布式服务器云主机 浏览:585
服务器忙打不开怎么办 浏览:17
tif压缩软件 浏览:415
程序员那么可爱陆漓上班第1天 浏览:952
macbookair自带什么app 浏览:703
如何关了加密的软件 浏览:583
程序员p2p待遇 浏览:923