10.4(MyPoint类)设计一个名为MyPoint的类
作者:互联网
设计一个名为Mypoint的类,代表一个以x坐标和y坐标表示的点。该类包括:
Java源代码:
class Mypoint{
double x,y;
Mypoint(double x,double y){
this.x =x;
this.y =y;
}
double distance(){
return Math.sqrt((Math.pow(this.x-0,2))+(Math.pow(this.y-0,2)));
}
double distance(double x,double y){
return Math.sqrt((Math.pow(this.x-x,2))+(Math.pow(this.y-y,2)));
}
// double distance(double x1,double y1,double x2,double y2){
// return Math.sqrt((Math.pow(x1-x2,2))+(Math.pow(y1-y2,2)));
// }
static double distance(Mypoint a,Mypoint b){
return Math.sqrt((Math.pow(a.x-b.x,2))+(Math.pow(a.y-b.y,2)));
}
}
public class Mypoint类 {
public static void main(String[] args) {
Mypoint a = new Mypoint(0,0);
Mypoint b = new Mypoint(10,30.5);
System.out.println(Mypoint.distance(a,b));
}
}
一定要根据题目要求,先将函数声明一个一个列出来,之后再一个一个进行补充实现。这就是套路。
标签:distance,10.4,double,sqrt,Mypoint,pow,MyPoint,Math,名为 来源: https://blog.csdn.net/MDeleter/article/details/121165619