Correction Examen 2
Correction Examen 2
Correction Examen 2
TRAVAIL A FAIRE
Correction
La classe Personne
public class Personne {
private String cin , nom;
private int anneeNaissance;
private static final int ANNEECOURANTE=2024;
public Personne(String cin , String nom , int anneeNaissance) {
this.cin=cin;
this.nom=nom;
this.anneeNaissance=anneeNaissance;
}
public String toString() {
return nom+" - "+cin+" - "+anneeNaissance;
}
public int age() {
return ANNEECOURANTE-anneeNaissance;
}
}
La classe Medecin
public class Medecin extends Personne{
private String specialite;
private int no;
private static int cptMedecin=0;
public Medecin(String cin , String nom , int anneeNaissance ,
String specialite) {
super(cin , nom , anneeNaissance);
this.specialite=specialite;
cptMedecin++ ;
no=cptMedecin ;
}
public String toString() {
return "Medecin:("+super.toString()+"-
Specilite("+specialite+"))\n";
}
}
La classe Patient
import java.util.Scanner;
import java.util.ArrayList;
public class Patient extends Personne{
private int no;
public static int nb=0;
private String cause;
//private Medecin medecin;
ArrayList <String> Medicaments=new ArrayList <String>();
public Patient(String cin , String nom ,int anneeNaissance, String cause) {
super(cin , nom ,anneeNaissance);
nb++;
this.no=nb;
this.cause=cause;
//this.medecin=medecin;
}
public void setCause(String cause) {
this.cause=cause;
}
public String getCause() {
return cause;
}
public void ajouterMed(String med) {
if(!Medicaments.contains(med))
Medicaments.add(med);
}
public String toString() {
String ch="";
ch+="Patient:"+super.toString()+" No:"+no+" Cause:"+cause+"\n" ;
//ch+=medecin.toString()+"\n"+"Medicaments:\n";
//for(String M:Medicaments)
//ch+=M+"\n";
return ch;
}
}
La classe Service
import java.util.ArrayList;
public class Service {
private String intitule;
private final int maxMedecin=2;
private final int maxPatient=20;
private ArrayList <Personne> listePersonnes = new ArrayList
<Personne>();
public Service (String intitule) {
this.intitule=intitule;
}
La classe Test_Service
import java.util.Scanner;
public class Test_Service {