Comparaison des objets Point dans Java

1/1
100%

public boolean equals(Object o){

public boolean equals(Object o){

Point tmp = (Point)o;

return((this.x==tmp.x)&&(this.y==tmp.y));

}

![](data:image/x-emf;base64...)p.equals(p2)

Point tmp = (Point)o;

Publicité

return((this.x==tmp.x)&&(this.y==tmp.y));

}

public String toString() {

return "The point x=" + x + ", y=" + y ;

}

public PointCol(int a, int b, String uneCouleur) {

super(a,b); //C’est obligatoire sinon 🡪 appel automatique à super()

Publicité

couleur = uneCouleur;

}

System.out.println(p.toString());

Ou :

System.out.println(lesComptes[0]);

// Création ET initialisation d'un tableau d'objets :

Etudiant[] tab = { new Etudiant("A", "B", 25, 12),

Publicité

new Etudiant("C", "D", 21, 17),

new Etudiant("E", "F", 27, 16),

new Etudiant("G", "H", 24, 13) };

// ou encore :

CompteBancaire[] lesComptes = new CompteBancaire[10]; //ou sans « 10 »

lesComptes[0]=cc1;

lesComptes[1]=ce1;

Publicité

rques :

  • On a créeé un tableau de comptes bancaires mais si on appelle n’importe quelle fct (ici : retirerArgent() et toString() ) il cherche le vrai type de l’objet

Comparaison des objets Point dans Java

Programming, Math, etc. · exam

Browse all programmation documents

public boolean equals(Object o){

public boolean equals(Object o){

Point tmp = (Point)o;

return((this.x==tmp.x)&&(this.y==tmp.y));

}

![](data:image/x-emf;base64...)p.equals(p2)

Point tmp = (Point)o;

Advertisement

return((this.x==tmp.x)&&(this.y==tmp.y));

}

public String toString() {

return "The point x=" + x + ", y=" + y ;

}

public PointCol(int a, int b, String uneCouleur) {

super(a,b); //C’est obligatoire sinon 🡪 appel automatique à super()

Advertisement

couleur = uneCouleur;

}

System.out.println(p.toString());

Ou :

System.out.println(lesComptes[0]);

// Création ET initialisation d'un tableau d'objets :

Etudiant[] tab = { new Etudiant("A", "B", 25, 12),

Advertisement

new Etudiant("C", "D", 21, 17),

new Etudiant("E", "F", 27, 16),

new Etudiant("G", "H", 24, 13) };

// ou encore :

CompteBancaire[] lesComptes = new CompteBancaire[10]; //ou sans « 10 »

lesComptes[0]=cc1;

lesComptes[1]=ce1;

Advertisement

rques :

  • On a créeé un tableau de comptes bancaires mais si on appelle n’importe quelle fct (ici : retirerArgent() et toString() ) il cherche le vrai type de l’objet