TD/TP5-6&7: Classes Abstraites et Interfaces : Partie 1 : (Classes Abstraites)
TD/TP5-6&7: Classes Abstraites et Interfaces : Partie 1 : (Classes Abstraites) : Exercice 1 : package abstractpersonne; public abstract class personne { protected String nom; protected String prenom; protected String rue; protected String ville; protected static int nbPersonnes=0; public personne(String nom, String prenom, String rue, String ville) { this.nom=nom; this.prenom=prenom; this.rue=rue; this.ville=ville; nbPersonnes ++; } public String toString() { return (nom+" "+prenom+" " + rue+" "+ ville); } public void modifierPersonne(String rue, String ville) { this.rue=rue; this.ville=ville; ecrirePersonne (); } static void nbPersonne() { System.out.println("\n Nombre d’employés : " + nbPersonnes + "\n Nombre de secrétaires : " + secretaire.nbSecretaires() + "\n Nombred’enseignants : " + Enseignant.nbEnseignants() + "\n Nombre d’étudiants : " + Etudiant.nbEtudiants()); } abstract void ecrirePersonne (); public static void main(String[] args) { secretaire soc = new secretaire ("Sara", "soufi","Rue de melahi", "rabat", "gt2534"); soc.ecrirePersonne(); Enseignant en = new Enseignant ("Ahmed", "Sbihi", "Rue de al farah", "tetouan", "1 ere annee renouvlable"); en.ecrirePersonne(); Etudiant et2 = new Etudiant ("ahmed", "koko","Rue asilal", "tanger", "3 eme annee genie civil"); et2.ecrirePersonne(); System.out.println ("\n l'affichage apres la modification:"); soc.modifierPersonne ("Rue de checha", "fes"); en.modifierPersonne ("Rue de afilal", "casablanca"); personne.nbPersonne(); } } ackage abstractpersonne; public class secretaire extends personne{ private String numeroBureau; private static int nbSecretaires = 0; secretaire (String nom, String prenom, String rue, String ville, String numeroBureau) { super (nom,prenom,rue,ville); this.numeroBureau = numeroBureau; nbSecretaires++; } public String toString () { return super.toString() + "\n Numero de bureau : " + numeroBureau; } void ecrirePersonne () { System.out.println ("Secrétaire : " + toString()); } static int nbSecretaires () { return nbSecretaires; } } package abstractpersonne; public class Etudiant extends personne { String diplomeEnCours; static int nbEtudiants; public Etudiant(String nom, String prenom, String rue, String ville, String diplomeEnCours) { super (nom,prenom,rue,ville); this.diplomeEnCours=diplomeEnCours; nbEtudiants++; } public String toString() { return super.toString() +"le diplome "+diplomeEnCours; } void ecrirePersonne () { System.out.println ("Etudiant : " + toString()); } static int nbEtudiants () { return nbEtudiants; } } package abstractpersonne; public class Enseignant extends personne{ private String specialite; private static int nbEnseignants = 0; public Enseignant (String nom, String prenom, String rue, String ville, String specialite) { super (nom, prenom, rue, ville); this.specialite = specialite; nbEnseignants++; } public String toString () { return super.toString() + "\n spécialité : " + specialite; } void ecrirePersonne () { System.out.println ("Enseignant : " + toString()); } static int nbEnseignants () { return nbEnseignants; }} Exercice2 : abstract class ObjetGraphique { protected int x, y; void ObjetGraphique() { x=0;y=0; } abstract void affiche (); public ObjetGraphique(int x, int y) { this.x=x; this.y=y; } public ObjetGraphique(ObjetGraphique Obj) { x =Obj.x; y =Obj.y; } public int getX() { return x; } public int getY() { return y; } public void setPosition(int x, int y) { this.x=x; this.y=y; } public void deplacer(int dx, int dy) { this.x=x+dx ; this.y=y+dy; }} public abstract class Rectangle extends ObjetGraphique{ double largeur, hauteur; public void Rectangle() { largeur=0; hauteur=0; } public Rectangle (int x, int y, double largeur, double hauteur) { super(x,y); this.largeur=largeur; this.hauteur=hauteur; } public void Rectangle(Rectangle Rec ) { x = Rec.x; y = Rec.y; largeur = Rec.largeur; hauteur = Rec.hauteur; } public double getHauteur(){ return hauteur; } public double getLargeur() { return largeur; } public void setObjetGraphique(int x, int y , double largeur, double hauteur) { super ( x , y ); this.largeur = largeur; this.hauteur = hauteur; } public void setTaille(double largeur, double hauteur) { this.largeur = largeur; this.hauteur = hauteur; } public void affiche() { System.out.println( "rectangle : "+getX()+" "+getY()+" "+getHauteur()+" "+getLargeur()); }} public class Bouton extends Rectangle{ String text ; public void Bouton() { super.Rectangle(); text=null; } Bouton(int x , int y, double largeur, double hauteur, String text) { super(x,y,largeur,hauteur); this.text= text; } public void Bouton(Bouton bot ) { x=bot.x; y=bot.y; hauteur=bot.hauteur; largeur=bot.largeur; text=bot.text; } public void setText(String text ) { this .text=text; } String getText() { return text; }} public class Cercle extends ObjetGraphique { double rayon ; public void Cercle() { rayon=0; } public Cercle(int x, int y, double rayon) { super(x,y); this.rayon=rayon; } public Cercle(Cercle Crcl ) { x=Crcl.x; y=Crcl.y; rayon=Crcl.rayon; } public void setRayon(double rayon) { this.rayon=rayon; } public double getRayon() { return rayon; } void affiche() { System.out.println("ce cercle a du rayon " +getRayon()); }} Partie 2 : (Interfaces) Exercice 3 (Gestion de stock d'un magasin) uploads/Geographie/ devoir-java2.pdf
Documents similaires
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/z09nTRihgUiNpYP9F2p6KSeFtTXhu1aeVWhtgYn9B1EubLVipxCqjZyShVRLWeikzRZ05GUODrq4yFF61VOygHPv.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/eXS23wvCZdhO2HeJJJ9kn9foNCcTgLOW1YRY5VwnhWEGygaRes5iy7MYbUdMcTREUCo8CB3s3i1aeivOSTO7UxcT.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/FPWTIZQtaRtbZZEo8bD3ZNUq7jP0WnvMM8sqB8Mz6eOif7Rr4hxItv5JfeIY5AOyERGmghStrOjIix2v82EUkM88.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/cuJRYwJlzAIs9zDlidIXYXATKVN4yJnwYOs4qyQSD2xByFe0WACidiHWuEUOx09FGiR7oS23c8aVSBJlidOmC5p7.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/xhr9mC89l0pS30tMKMaSEtoYmTjLxJDrXdX8nVM0Avu623PKjiPihVltzPnIabM06KmLSceM5bE5Ukonz9IHeGgY.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/zT0CdCAE8D6QE3XphdO8UVYWTlUdrI9coECbc1j3SntJdjs49J6NP35VIC7NkcZ1dabmIoZ9AhykUdQ3AujL37Yq.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/GpWEHoLtngyG7h98Z7niLSDKEsCPBGSXwB9fNo1ZpX0VwXk1vENAm6NLyuBGDx80RZe711iGyiBPyfTD3udVu095.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/hBfDKzk8UXGCxUG3rUZiztYuojUMkNTjtuzVovxXCHDOJATHKA0pHUs3b0XEK6fNH5vYkfZli3Iv6wOnyHmtekQN.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/Wp7bTJCpwn6OjU4aOqQRrKuR8MPVQNdHq3TjgLf2jf4bQfeSXoOBFDV12oyXvQHH7bbDNwIAweAXQjQx86S7apBF.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/kGXw6aC6BBIsiae9hDfnsV7S1Gvxsgpe5NoMjUzNzblUhNAmw98XyX6bzp6NUphQEC2LYJFr6fYeLPeh7DzWpnG7.png)
-
21
-
0
-
0
Licence et utilisation
Gratuit pour un usage personnel Attribution requise- Détails
- Publié le Fev 10, 2022
- Catégorie Geography / Geogra...
- Langue French
- Taille du fichier 0.1054MB