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

热点内容
高尔夫电台怎么添加到文件夹 浏览:237
四川麻将一般下哪个app 浏览:862
反编译exe脚本 浏览:460
源码文件夹怎么编译到固件中 浏览:910
ERp打印服务器错误怎么弄 浏览:111
蚌端口u盘加密软件有哪些 浏览:178
前端如何认证服务器 浏览:554
linux切换db2用户命令 浏览:308
相片如何用电解压 浏览:906
硕士程序员去学校当老师 浏览:120
pythonstr提取到字典 浏览:818
程序员那么可爱有人看上陆漓了 浏览:878
php正则提取图片 浏览:105
pythonlinuxdjango 浏览:562
php中文返回乱码 浏览:91
宿舍装的电信怎么加密 浏览:745
为什么压缩文件解压后变少了 浏览:426
现在安卓充电器普遍是什么型号 浏览:714
9日均线36均线主图指标源码 浏览:351
程序员阿里文化完整版 浏览:98