Skip to content

Instantly share code, notes, and snippets.

@adilmezghouti
Last active December 28, 2021 22:56
Show Gist options
  • Save adilmezghouti/d56a276845331d30352c to your computer and use it in GitHub Desktop.
Save adilmezghouti/d56a276845331d30352c to your computer and use it in GitHub Desktop.
POO
abstract class Forme {
protected String couleur;
public void changerCouleur(String nouveauCouleur){
this.couleur = nouveauCouleur;
}
protected abstract void deplacer(float dx, float dy);
}
class Cercle extends Forme {
private float x, y;
public void deplacer(float dx, float dy){
this.x = this.x + dx;
this.y = this.y + dy;
}
}
class Triangle extends Forme {
private float x1, x2, x3;
private float y1, y2, y3;
public void deplacer(float dx, float dy) {
this.x1 += dx;
this.x2 += dx;
this.x3 += dx;
this.y1 += dy;
this.y2 += dy;
this.y3 += dy;
}
}
public static void main(String[] args){
Forme cercle = new Cercle();
Forme triangle = new Triangle();
List<Forme> formes = new ArraysList<>();
formes.add(cercle);
formes.add(tringle);
for(Forme forme:formes){
forme.deplacer(5,7);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment