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
|
public class Points1
{
double x; char nom;
public Points1 (char nom,double x)
{
this.x=x;
this.nom=nom;
}
public void afficherCoord ()
{
System.out.println ("Le Point "+this.nom+" a pour abscisse "+x );
}
public double distance (Points1 M)
{
double d=this . x M . x ;
return Math.abs (d);
}
public void deplacer (double dx)
{
this.x+=dx;
}
}
public class TesterPoints1
{
public static void main (String[] args)
{
Points1 A=new Points1 ( 'A', 2.6);
A.afficherCoord ();
A.deplacer (1.1);
A.afficherCoord ();
Points1 B=new Points1 ( 'B', 1.54);
B.afficherCoord ();
System.out.println ("Distance entre A et B = "+A.distance (B));
}
} |