java问题 定义一个Point点类 10
定义一个Point点类,成员变量有x,y,成员函数set()设置x,y的值,get()获取x,y的值,并定义一个点对象调用set()和get(),并定义一个点对象调用se...
定义一个Point点类,成员变量有x,y,成员函数set()设置x,y的值,get()获取x,y的值,并定义一个点对象调用set()和get(),并定义一个点对象调用set()和get()构造方法重载,distance()表示2点间的距离。
展开
展开全部
public class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public double distance(Point p1,Point p2){
return Math.sqrt((p2.getX()-p2.getX())*(p2.getX()-p2.getX())+(p2.getY()-p1.getY())*(p2.getY()-p1.getY()));
}
public static void main(String args[]){
Point p1 = new Point(14,17);
Point p2 = new Point(23,90);
double s = p1.distance(p1,p2);
System.out.println("2点之间的距离为:"+s);
}
}
2020-04-19
展开全部
package test1;
public class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x; }
public void setX(int x) {
this.x = x; }
public int getY() {
return y; }
public void setY(int y) {
this.y = y; }
public double distance(Point p1, Point p2){
return Math.sqrt((p2.getX()-p1.getX())*(p2.getX()-p1.getX())+(p2.getY()-p1.getY())*(p2.getY()-p1.getY()));
}
public void displayPoint (int x, int y){
System.out.println("x:"+x+",y:"+y);
}
public static void main(String args[]){
Point p1 = new Point(10,20);
Point p2 = new Point(35,25);
Point a1=new displaypoint(10,20);
a2= new displaypoint(35,25);
double s = p1.distance(p1,p2);
System.out.println("2点之间的距离为:"+s);
}
}
public class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x; }
public void setX(int x) {
this.x = x; }
public int getY() {
return y; }
public void setY(int y) {
this.y = y; }
public double distance(Point p1, Point p2){
return Math.sqrt((p2.getX()-p1.getX())*(p2.getX()-p1.getX())+(p2.getY()-p1.getY())*(p2.getY()-p1.getY()));
}
public void displayPoint (int x, int y){
System.out.println("x:"+x+",y:"+y);
}
public static void main(String args[]){
Point p1 = new Point(10,20);
Point p2 = new Point(35,25);
Point a1=new displaypoint(10,20);
a2= new displaypoint(35,25);
double s = p1.distance(p1,p2);
System.out.println("2点之间的距离为:"+s);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Point {
private float x,y;
public Point(float x,float y){
this.x=x;
this.y=y;
}
public float getX() {
return x;
}
public void setX(float x) {
this.x = x;
}
public float getY() {
return y;
}
public void setY(float y) {
this.y = y;
}
public double distance(Point p){
return Math.sqrt((p.getX()-x)*(p.getX()-x)+(p.getY()-y)*(p.getY()-y));
}
}
private float x,y;
public Point(float x,float y){
this.x=x;
this.y=y;
}
public float getX() {
return x;
}
public void setX(float x) {
this.x = x;
}
public float getY() {
return y;
}
public void setY(float y) {
this.y = y;
}
public double distance(Point p){
return Math.sqrt((p.getX()-x)*(p.getX()-x)+(p.getY()-y)*(p.getY()-y));
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询