1)Ondonnedansunétablissementscolaire:*PourIJoignable:publicStringgetEmail();//renvoiemailpublicStringgetPhone();//renvoinumérotéléphone*Pourunepersonnedel'établissement :
Nom, prenom // compléter liste attributs
void Affiche() // Entête seulement //Compléter méthodes
* Pour un étudiant
// compléter liste attributs void Affiche() // Affiche nom, prénom et classe
* Pour un professeur
// compléter liste attributs void Affiche() {} // Affiche nom, prénom et spécialité
Sachant que chaque etudiant et professeur est une personne, et qu'unepersonneestIJoignable,EcrisenJavalaclasseIJoignableainsiquelesclassesPersonne,EtudiantetProfesseur.Lesconstructeursrenfermenttoutlesattributsdechaqueclasse.2)DanslaméthodemainduprogrammeprincipalPPEtablissement:a)Créerunepersonne (justifiers'il y a probléme)
b) Créer 3 étudiants et 2 professeurs
c) Créer une liste de Personne
d) Ajouter les étudiants et les professeurs dans la liste
e) Afficher les informations des professeurs et étudiants de la liste
f) -Retirer le dernier enregistrement de la liste
Réponses :
Classe IJoignable :
public interface IJoignable {
public String getEmail();
public String getPhone();
}
Classe Personne :
public class Personne implements IJoignable {
private String nom;
private String prenom;
private String email;
private String phone;
public Personne(String nom, String prenom, String email, String phone) {
this.nom = nom;
this.prenom = prenom;
this.email = email;
this.phone = phone;
}
public String getNom() {
return nom;
}
public String getPrenom() {
return prenom;
}
@Override
public String getEmail() {
return email;
}
@Override
public String getPhone() {
return phone;
}
public void Affiche() {
System.out.println(nom + "" + prenom);
}
}
Classe Etudiant :
public class Etudiant extends Personne {
private String classe;
public Etudiant(String nom, String prenom, String email, String phone, String classe) {
super(nom, prenom, email, phone);
this.classe = classe;
}
public String getClasse() {
return classe;
}
@Override
public void Affiche() {
super.Affiche();
System.out.println("Classe : " + classe);
}
}
Classe Professeur :
public class Professeur extends Personne {
private String specialite;
public Professeur(String nom, String prenom, String email, String phone, String specialite) {
super(nom, prenom, email, phone);
this.specialite = specialite;
}
public String getSpecialite() {
return specialite;
}
@Override
public void Affiche() {
super.Affiche();
System.out.println("Spécialité : " + specialite);
}
}
Programme principal
PPEtablissement :
import java.util.ArrayList;
import java.util.List;
public class PPEtablissement {
public static void main(String[] args) {
// a) Créer une personne
Personne personne = new Personne("Doe", "John", "johndoe@mail.com", "01.23.45.67.89");
// Cette personne ne peut pas être utilisée comme un étudiant ou un professeur car elle n'apasdeclasseoudespécialité.//b)Créer3étudiantset2professeursEtudiantetudiant1=newEtudiant("Dupont","Alice","alice.dupont@mail.com","06.12.34.56.78","1A");Etudiantetudiant2=newEtudiant("Martin","Bob","bob.martin@mail.com","06.23.45.67.89","2B");Etudiantetudiant3=newEtudiant("Lefevre","Claire","claire.lefevre@mail.com","06.34.56.78.90","1A");Professeurprofesseur1=newProfesseur("Durand","Eric","eric.durand@mail.com","01.23.45.67.89","Mathématiques");Professeurprofesseur2=newProfesseur("Girard","Françoise","francoise.girard@mail.com",//c)CréerunelistedePersonneList<Personne>listePersonnes=newArrayList<>();//d)AjouterlesétudiantsetlesprofesseursdanslalistelistePersonnes.add(etudiant1);listePersonnes.add(etudiant2);listePersonnes.add(etudiant3);listePersonnes.add(professeur1);listePersonnes.add(professeur2);//e)AfficherlesinformationsdesprofesseursetétudiantsdelalisteSystem.out.println("Liste des personnes :");for (Personnepersonne:listePersonnes){personne.Affiche();}//f)RetirerledernierenregistrementdelalistelistePersonnes.remove(listePersonnes.size()-1);System.out.println("Liste des personnes après suppression :");for (Personnepersonne:listePersonnes){personne.Affiche();}}}Note:cetteimplémentationestbasiqueetnegèrepasleséventuellesexceptionsliéesauxentréesutilisateurouàlamanipulationdelistesvides.
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.