Vous êtes sur la page 1sur 1

     recherche ...

ACCUEIL EXERCICES EXAMENS CONTACT CONNEXION

Accueil / Exercices / Programmation / Java / Association Professeur / Spécialité

Association Professeur / Spécialité


07 Mar
2016

 LACHGAR |  Java |  Chapitre: Classes et Objets |  26693 visites |  Facile |   Corrigé

 Enoncé  Solution  Code Complet  Pièces jointes


 TÉLÉCHARGEMENT
Structure de projet 
Codes Sources

Outils de développement

Utilitaires

Outils en ligne

Structure de projet

 La classe Spécialité 

1. package ma.exelib.projet.ecole;
2.
3. public class Specialite {
4. private int id;
5. private String code;
6. private String libelle;
7. private static int count;
8.
9. public Specialite(String code, String libelle) {
10. this.id = ++count;
11.
12. this.code = code;
13. this.libelle = libelle;
14. }
15.
16. public int getId() {
17. return id;
18. }
19.
20. public void setId(int id) {
21. this.id = id;
22. }
23.
24. public String getCode() {
25. return code;
26. }
27.
28. public void setCode(String code) {
29. this.code = code;
30. }
31.
32. public String getLibelle() {
33. return libelle;
34. }
35.
36. public void setLibelle(String libelle) {
37. this.libelle = libelle;
38. }
39.
40. public static int getCount() {
41. return count;
42. }
43.
44. public static void setCount(int count) {
45. Specialite.count = count;
46. }
47.
48. public String toString() {
49. return "Spécialité "+ this.libelle;
50. }
51.
52. }

 La classe Professeur 

1. package ma.exelib.projet.ecole;
2.
3. public class Professeur {
4. private int id;
5. private String nom;
6. private String prenom;
7. private String telephone;
8. private String email;
9. private Specialite specialite;
10. private static int count;
11.
12. public Professeur(String nom, String prenom, String telephone,
13. String email, Specialite specialite) {
14. this.id = ++count;
15. this.nom = nom;
16. this.prenom = prenom;
17. this.telephone = telephone;
18. this.email = email;
19. this.specialite = specialite;
20. }
21.
22. public int getId() {
23. return id;
24. }
25.
26. public void setId(int id) {
27. this.id = ++count;
28. }
29.
30. public String getNom() {
31. return nom;
32. }
33.
34. public void setNom(String nom) {
35. this.nom = nom;
36. }
37.
38. public String getPrenom() {
39. return prenom;
40. }
41.
42. public void setPrenom(String prenom) {
43. this.prenom = prenom;
44. }
45.
46. public String getTelephone() {
47. return telephone;
48. }
49.
50. public void setTelephone(String telephone) {
51. this.telephone = telephone;
52. }
53.
54. public String getEmail() {
55. return email;
56. }
57.
58. public void setEmail(String email) {
59. this.email = email;
60. }
61.
62. public Specialite getSpecialite() {
63. return specialite;
64. }
65.
66. public void setSpecialite(Specialite specialite) {
67. this.specialite = specialite;
68. }
69.
70. public String toString() {
71. return "-" + this.nom.toUpperCase() + " "
72. + this.prenom.substring(0, 1).toUpperCase() + ""
73. + this.prenom.substring(1).toLowerCase() + " " + this.email;
74. }
75.
76. }

 La classe de Test

package ma.exelib.projet.ecole.test;

import ma.exelib.projet.ecole.Professeur;
import ma.exelib.projet.ecole.Specialite;

public class Test {


public static void main(String[] args) {
Specialite[] specialites = new Specialite[5];
// Création des spécialités
specialites[0] = new Specialite("S1", "JAVA/JEE");
specialites[1] = new Specialite("S2", ".net");
specialites[2] = new Specialite("S3", "Gestion de projet");
specialites[3] = new Specialite("S4", "CISCO");
specialites[4] = new Specialite("S5", "PHP");

// Création des professeurs


Professeur professeurs[] = new Professeur[4];
professeurs[0] = new Professeur("Safi", "salim", "0656787567",
"safi [AT] gmail [DOT] com", specialites[0]);
professeurs[1] = new Professeur("Rami", "amal", "0654487567",
"rami [AT] gmail [DOT] com", specialites[3]);
professeurs[2] = new Professeur("Rashidi", "Mohamed", "0656777567",
"rashidi [AT] gmail [DOT] com", specialites[0]);
professeurs[3] = new Professeur("Simon", "thomas", "0654445567",
"simon [AT] gmail [DOT] com", specialites[3]);

// Professeur par spécialité


System.out.println("Professeur par spécialité : ");
for (Specialite s : specialites) {
System.out.println("\t" + s);
int etat = 0;
for (Professeur p : professeurs) {
if (p.getSpecialite().getId() == s.getId()) {
System.out.println("\t\t" + p);
etat = 1;
}
}
if (etat == 0) {
System.out.println("\t\tAucun professeur dans cette spécialité");
}
}

Exercices du même chapitre Exercices du même auteur

Association Etudiant / Filière Examen - Java - 2012 - 2013

La classe Voiture Gestion de location des voitures en C

La classe Rectangle Conception d'un système de suivi des projets

La classe Livre La classe Voiture

Classe Point Simple Gestion des salles avec les collections

Evaluez cet article :Note moyenne 7 votes

Tags : classe | objet | static | String

Ajoutez aux favoris : Cliquez pour ajouter cet article à vos favoris

Dernière modi cation : 8-03-16 12:26

Share

Dans la même catégorie


Nombre Armstrong

Gestion des salles avec les collections

Tri d'une collection d'objet

Interface et classe abstraite : Classes Complexe et Réel

Héritage à plusieurs niveaux

 NOUVEAUX EXERCICES  EXERCICES POPULAIRES

Gestion de location des voitures en C Gestion d'un stock


Langage C Programmation Orientée Objet

Factorielle inversée Créer un formulaire d'inscription en html


Langage C HTML

File d’attente d’une imprimante Classe Etudiant


Langage C Langage C++

Surcharge des opérateurs de la classe Fraction Polymorphisme - La classe Personne


Langage C++ Programmation Orientée Objet

Nombre Armstrong La classe Compte


Java Programmation Orientée Objet

Sauvegarde et lecture d'un tableau d'étudiants dans un chier texte Gestion de location des voitures en C
Langage C Langage C

 NOUVEAUX EXAMENS  EXAMENS POPULAIRES

EFM Applications Hypermédias – 2016-2017 EFM - SGBD 1 - 2014-2015


Examens TDI Examens TDI

EFM - Algorithme - 2015-2016 EFM - Langage C - 2014-2015


Examens TDI Examens TDI

EFM - Langage C - 2015-2016 EFM - Programmation orientée objet - 2014-2015


Examens TDI Examens TDI

EFM - Programmation événementielle - 2015-2016 Examen - Java - 2012 - 2013


Examens TDI Examens CRJJ

EFM - Programmation orientée objet - 2015-2016 EFM - Langage C - 2015-2016


Examens TDI Examens TDI

EFM - Programmation événementielle - 2014-2015 EFM - Algorithme - 2013-2014


Examens TDI Examens TDI

L'équipe Politique de con dentialité Contact Faq Plan du site    

Copyright © 2017 - exelib.net - Tous droits réservés 

Le contenu de ce site est fourni dans un but d'apprentissage et de partage d'information et ne peut en aucun cas remplacer le travail effectué en classe.

Vous aimerez peut-être aussi