Created
March 5, 2015 19:44
-
-
Save Ilyes-Hammadi-Ahmed/3965efd8481705ea901a to your computer and use it in GitHub Desktop.
exercice 7 fiche TP 3 IPOO version POO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.company; | |
| public class Main { | |
| public static void main(String[] args) { | |
| // write your code here | |
| Rectangle rectangle = new Rectangle(8, 20); | |
| rectangle.affiche(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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