Dans
cette vidéo jai reprit l'exercice 7 de la fiche TD 3 IPOO et je lé
coder d'une manière Orienter Objet avec intellij IDEA un IDE que je vous
conseille de télécharger et d'utiliser dans votre apprentissage du
langage JAVA .
code source >>
code source >>
This file contains 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 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 { | |
// attributs | |
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(); | |
} | |
} |
0 comments:
Post a Comment