public class point{
float x;
float y;
public point(float x,float y){
this.x=x;
this.y=y;
}
void afficher(){
System.out.println("point("+x+","+y+")");
}
void deplacer(float a,float b){
x=a;
y=b;
}
float getAbscisse(){
return this.x;
}
float getOrdonne(){
return this.y;
}
public String toString(){
String ch;
ch="le point est "+ this.x +"\t"+this.y;
return ch;
}
public Boolean equals(point po){
return po!= null && po.equals(this.x) && po.equals(this.y);}
public static void main (String [] args){
point p=new point(19,4);
p.afficher();
System.out.println(p);
p.deplacer(6,8);
p.afficher();
point p2=new point(6,8.0f);
point p3=new point(4.0f, 2.0f);
System.out.println("p est egal a p2:"+p.equals(p2));
System.out.println("p est egal a p3:"+p.equals(p3));
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter