Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. public class Point {
  2.     private double x;
  3.     private double y;
  4.    
  5.     public Point(){
  6.         x= 0.0;
  7.         y= 0.0;
  8.     }
  9.    
  10.     public Point(double vx, double vy){
  11.         x = vx;
  12.         y = vy;
  13.     }
  14.    
  15.     public double getX(){
  16.         return x;
  17.     }
  18.    
  19.     public double getY(){
  20.         return y;
  21.     }
  22.    
  23.     public double distanceTo(Point p){
  24.         return Math.sqrt(Math.pow(x-p.x, 2) + Math.pow(y-p.y, 2));
  25.     }
  26.    
  27.     public static void main(String args[]){
  28.         Point a,b;
  29.         a = new Point();
  30.         b = new Point(2.0,2.0);
  31.         double d;
  32.         d=a.distanceTo(b);
  33.         System.out.println("La distance est : " + d);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement