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

热点内容
编程珠玑笔记 浏览:279
结束命令行 浏览:268
力学原理pdf 浏览:734
宏定义编译后不变 浏览:404
如何搞免费服务器 浏览:212
神经系统pdf 浏览:672
如何查看服务器上的数据库服务器 浏览:195
压缩机型号v代表什么 浏览:57
旅游类源码 浏览:867
电脑服务器类型怎么设置 浏览:235
pdf炒股 浏览:791
服务器地址缺少端口号什么意思 浏览:535
下载需要解压的小说用哪个软件 浏览:539
广东分布式服务器云主机 浏览:588
服务器忙打不开怎么办 浏览:20
tif压缩软件 浏览:418
程序员那么可爱陆漓上班第1天 浏览:952
macbookair自带什么app 浏览:706
如何关了加密的软件 浏览:587
程序员p2p待遇 浏览:923