[go: up one dir, main page]

0% found this document useful (0 votes)
215 views4 pages

Corrig+® Exam Java Contrl Esprit

The document contains code defining classes for Patients, Doctors, and a Hospital. The Patient and Doctor classes define toString(), equals(), and compareTo() methods. The ListPatients class manages a list of Patients with methods like add(), remove(), search(), sort(), and display(). The SetMedecins class manages a set of Doctors. The Hospital class manages a map of Doctors to their patient lists, with methods to add Doctors, add Patients, and display the doctor-patient mappings.

Uploaded by

PFE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
215 views4 pages

Corrig+® Exam Java Contrl Esprit

The document contains code defining classes for Patients, Doctors, and a Hospital. The Patient and Doctor classes define toString(), equals(), and compareTo() methods. The ListPatients class manages a list of Patients with methods like add(), remove(), search(), sort(), and display(). The SetMedecins class manages a set of Doctors. The Hospital class manages a map of Doctors to their patient lists, with methods to add Doctors, add Patients, and display the doctor-patient mappings.

Uploaded by

PFE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1) @Override

public String toString() {


1 return "Patient{" + "cin=" + cin + "nom=" + nom + "prenom=" +
prenom + "numSecuriteSociale=" + numSecuriteSociale + '}';
}

2)@Override
public boolean equals(Object obj) {
if (obj == null) {
1 return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Patient other = (Patient) obj;
if (this.cin != other.cin) {
return false;
}
if (this.numSecuriteSociale != other.numSecuriteSociale) {
return false;
}
return true;
}

3)

0,5 public class TriNomPatient implements Comparator<Patient>{

4) public int compare(Patient p1, Patient p2) {


0,5 return p1.getNom().compareTo(p2.getNom());
}

5)
0,5 public class ListPatients implements InterfacePatient{

private List<Patient> listP;

public ListPatients(){
0,5 listP=new ArrayList<Patient>();
}

public void ajouterPatient(Patient p) {


0,5 listP.add(p);
}

public void supprimerPatient(Patient p) {


0,5 listP.remove(p);
}

public boolean rechercherPatient(Patient p){


0,5 return listP.contains(p);
}
10)
1 public boolean rechercherPatient(int cin) {
for(Patient p : listP){
if(p.getCin()==cin){
return true;
}
}
return false;
}

11)

1 public void afficherPatients() {


for(Patient p:listP){
System.out.println(p);
}
}

12)

1 public void trierPatientsParNom() {


Collections.sort(listP, new TriNomPatient());
}

13)

0,5 public class Medecin implements Comparable<Medecin>{

14)
@Override
1 public String toString() {
return "Medecin{" + "cin=" + cin + "nom=" + nom + "prenom=" +
prenom + "numOrdre=" + numOrdre + '}';
}

15)
@Override
1 public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Medecin other = (Medecin) obj;
if (this.cin != other.cin) {
return false;
}
if (this.numOrdre != other.numOrdre) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
return hash;
}

16)

2 public int compareTo(Medecin o) {


if(this.cin<o.getCin())
return -1;
else if(this.cin==o.getCin())
return 0;
else
return 1;
}

17)
0,5 public SetMedecins(){
setM=new HashSet<Medecin>();
}

18)
0,5 public void ajouterMedecin(Medecin m) {
setM.add(m);
}

19)
1 public boolean rechercherMedecin(int cin) {
for(Medecin m : setM){
if(m.getCin()==cin){
return true;
}
}
return false;
}

20)
1 public void afficherMedecins() {
for(Medecin m : setM){
System.out.println(m);
}
}

21)
0,5 public Hopital(){
medecinPatiens=new TreeMap<Medecin, ListPatients>();
}

22)
0,5 public void ajouterMedecin(Medecin m){
ListPatients lp=new ListPatients();
medecinPatiens.put(m, lp);
}
public void ajouterPatient(Medecin m,Patient p) throws
MedecinException{
if(medecinPatiens.containsKey(m)){
23)
1 medecinPatiens.get(m).ajouterPatient(p);

}else {
24)
1 ListPatients lp=new ListPatients();
lp.ajouterPatient(p);
medecinPatiens.put(m, lp); } }
25)
1 public void afficherMap(){
for(Map.Entry<Medecin,ListPatients> m: medecinPatiens.entrySet()){
System.out.println(m.getKey()+" \t ");
m.getValue().afficherPatients();
}
}

You might also like