Skip to content

Instantly share code, notes, and snippets.

@Ilyes-Hammadi-Ahmed
Created March 5, 2015 19:44
Show Gist options
  • Select an option

  • Save Ilyes-Hammadi-Ahmed/3965efd8481705ea901a to your computer and use it in GitHub Desktop.

Select an option

Save Ilyes-Hammadi-Ahmed/3965efd8481705ea901a to your computer and use it in GitHub Desktop.
exercice 7 fiche TP 3 IPOO version POO
package com.company;
public class Main {
public static void main(String[] args) {
// write your code here
Rectangle rectangle = new Rectangle(8, 20);
rectangle.affiche();
}
}
package com.company;
/**
* Created by Tor on 05/03/2015.
*/
public class Rectangle {
// atributs
private int hauteur;
private int largeur;
// constructor
public Rectangle(int hauteur, int largeur) {
this.hauteur = hauteur;
this.largeur = largeur;
}
// setters
public void setHauteur(int hauteur) {
this.hauteur = hauteur;
}
public void setLargeur(int largeur) {
this.largeur = largeur;
}
// getters
public int getHauteur() {
return hauteur;
}
public int getLargeur() {
return largeur;
}
// methods
// methode qui affiche la premiere ligne:
private void ligne(){
System.out.print("+");
for (int i = 1; i <= this.largeur ; i++) {
System.out.print("-");
}
System.out.print("+");
}
// methode qui affiche tous les rectangle
public void affiche(){
ligne();
System.out.println(); // saut de ligne
for (int i = 1; i <= this.hauteur; i++) {
System.out.print("|");
for (int j = 1; j <= this.largeur; j++) {
System.out.print(" ");
}
System.out.print("|");
System.out.println(); // saut de ligne
}
ligne();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment