猿问

JAVA编程定义一个点类。?

JAVA编程定义一个点类。 


素胚勾勒不出你
浏览 815回答 3
3回答

Qyouu

1234567891011121314151617181920212223242526272829303132333435public class Point {         private double x;         private double y;         public Point(double x, double y) {        super();        this.x = x;        this.y = y;    }     public double distance(Point point) {        return Math.sqrt((point.x - this.x) * (point.x - this.x) + (point.y - this.y) * (point.y - this.y));    }         public Point move(double x, double y) {        return new Point(this.x + x, this.y + y);    }         @Override    public String toString() {        // TODO Auto-generated method stub        return "(" + x + ", " + y + ")";    }         public static void main(String[] args) {        Point p1 = new Point(5, 6);        Point p2 = new Point(-2, -9);                 System.out.println(p1.distance(p2));        System.out.println(p1.move(11, -2));    }     }

有只小跳蛙

class Point{      int x;      int y;      public Point(int x,int y){          this.x = x;          this.y = y;      }             public void move(){      //要怎么移动。。。      }      public void test(){      //要测试什么。。。      }}
随时随地看视频慕课网APP

相关分类

Java
MySQL
我要回答