1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| public class Point2D {
//attibuts
private double x;
private double y;
//Premier Constructeur
public Point2D (){
}
//2 eme constructeur a 2 arguments
public Point2D (double x , double y ){
this.x = x;
this.y = y;
}
//3 eme constructeur
public Point2D (Point2D p){
//Point2D p1= new Point2D();
this.x = p.x;
this.y = p.y;
}
//Get
public double getX(){
return this.x;
}
public double getY (){
return this.y;
}
//Set
public void setX (double x){
this.x = x;
}
public void setY (double y ){
this.y = y;
}
//Methode deplace
public void deplace (double x , double y){
this.x +=x;
this.y +=y;
}
//Methode string afficher les coordonnées du Point
public String toString(){
String s = "(" + this.x + " , " +this.y + ")";
return s;
}
//Methode distance entre 2 points
public double distance (Point2D p){
double distance;
distance = Math.sqrt((this.x- p.x ) * (this.x- p.x) + (this.y-p.y)* (this.y - p.y));
return distance;
}
//Methode saisir
public void saisir(){
System.out.print ( " Saisir une abcisse x = ");
this.x = Lire.reelDouble();
System.out.print ( " Saisir une ordonnée y = ");
this.y = Lire.reelDouble();
}
//Methode Symetrique
public Point2D sym_o (){
Point2D symetrique = new Point2D (this.y,this.x);
return symetrique
}
} |
Partager