Triangle

Résolu
JordAan Messages postés 3 Date d'inscription   Statut Membre Dernière intervention   -  
JordAan Messages postés 3 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,
Je suis actuellement en école d'ingénieur, et je dois réaliser un triangle hérité d'une classe Point, mais je ne sais pas comment introduire trois points à partir d'une seule classe Point.
Pourriez-vous m'aider ?
Merci d'avance.
A voir également:

2 réponses

irmeche Messages postés 71 Date d'inscription   Statut Membre Dernière intervention   17
 
tu créer trois objets de type points

Point p1 = new Point();
Point p2 = new Point();
Point p3 = new Point();

// ou
Point p1 = new Point(x1, y1);
Point p2 = new Point(x2, y2);
Point p3 = new Point(x3, y3);
0
JordAan Messages postés 3 Date d'inscription   Statut Membre Dernière intervention  
 
Merci
Voilà ce que j'avais fait initialement mais cela ne fonctionne pas.

public class Triangle extends Point{
Point[] p = new Point[3];
Triangle(int a1, int b1, int a2, int b2, int a3, int b3)
{
p[0] = new Point(a1, b1);
p[1] = new Point(a2, b2);
p[2] = new Point(a3, b3);
}
0
JordAan Messages postés 3 Date d'inscription   Statut Membre Dernière intervention  
 
finalement ça a l'air de marcher :
public class Triangle extends Point{
Point[] p = new Point[3];
public Triangle (int a, int b, int c, int d, int e, int f)
{
p[0] = new Point(a, b); // premier point
p[1] = new Point(c, d); // second point
p[2] = new Point(e, f); //troisième point
}

public String toString() {
return "point 1 = " + p[0]
+ " , "+ "point 2 = " + p[1]
+ " , " +"point 3 = " + p[2] ;
}
}
0