Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedList;
- public class Service {
- private String designation;
- private Cadre responsable;
- private String description;
- private LinkedList<Employe> mes_employes;
- private LinkedList<Cadre> mes_cadres;
- public Service() {
- this.designation = this.description = "";
- this.responsable = new Cadre();
- this.mes_cadres = new LinkedList<Cadre>();
- this.mes_employes = new LinkedList<Employe>();
- }
- public void saisir() {
- System.out.println("Donner designation :");
- this.designation = Console.saisir_chaine();
- System.out.println("Donner description :");
- this.designation = Console.saisir_chaine();
- }
- public void afficher() {
- System.out.println("Donner designation :" + this.designation);
- System.out.println("Donner description :" + this.description);
- System.out.println("Donner responsable service :");
- this.responsable.afficher();
- System.out.println("Ce service a : " + this.mes_cadres.size() + " cadres");
- System.out.println("Ce service a : " + this.mes_employes.size() + " employes");
- }
- public void ajouter_employe() {
- Employe e = new Employe();
- e.saisir();
- this.mes_employes.add(e);
- System.out.println("Employe ajouter avec succes");
- }
- public void ajouter_cadre() {
- Cadre c = new Cadre();
- c.saisir();
- this.mes_cadres.add(c);
- System.out.println("Cadre ajouter avec succes");
- }
- public void lister() {
- System.out.println("Liste des employés :");
- for (int i = 0; i < this.mes_employes.size(); i++) {
- this.mes_employes.get(i).afficher();
- }
- System.out.println("Liste des employés :");
- for (int i = 0; i < this.mes_employes.size(); i++) {
- this.mes_employes.get(i).afficher();
- }
- }
- public void supprimer() {
- int num = 0;
- boolean trouve = false;
- int i = 0;
- String choix = "";
- System.out.println("Cdre C ou employe E :");
- choix = Console.saisir_chaine();
- System.out.println("Donner numéro personne à retirer :");
- num = Console.saisir_entier();
- if(choix.equalsIgnoreCase("E")){
- while (i < this.mes_employes.size() && trouve == false) {
- if(num == this.mes_employes.get(i).GetNumpPers())
- trouve = true;
- else
- i++;
- }
- if(trouve){
- this.mes_employes.get(i).afficher();
- System.out.println("Employe retiré");
- this.mes_employes.remove(i);
- }
- else
- System.out.println("Erreur de numéro");
- }
- else{
- while (i < this.mes_cadres.size() && trouve == false) {
- if(num == this.mes_cadres.get(i).GetNumpPers())
- trouve = true;
- else
- i++;
- }
- if(trouve){
- this.mes_cadres.get(i).afficher();
- System.out.println("Cadre retiré");
- this.mes_cadres.remove(i);
- }
- else
- System.out.println("Erreur de numéro");
- }
- }
- public String toXml() {
- String xml = "";
- xml = xml + "<service>" + "/n";
- xml = xml + "<designation>" + this.designation + "</designation>" + "/n";
- xml = xml + "<description>" + this.description + "</description>" + "/n";
- xml = xml + "<directeur>" + "\n";
- xml = xml + this.responsable.toXml();
- xml = xml + "</directeur>" + "\n";
- xml = xml + "<liste _e>" + "\n";
- for (int i = 0; i < this.mes_cadres.size(); i++) {
- xml = xml + this.mes_cadres.get(i).toXml();
- }
- xml = xml + "</liste_e>" + "\n";
- xml = xml + "</service>" + "\n";
- return xml;
- }
- public void gerer(){
- int choix;
- do {
- System.out.println("Menu");
- System.out.println("1. Saisir");
- System.out.println("2. Afficher");
- System.out.println("3. Ajouter Employe");
- System.out.println("4. Ajouter Cadre");
- System.out.println("5. Lister");
- System.out.println("6. Supprimer");
- System.out.println("7. XML");
- System.out.println("0. Quitter");
- System.out.println("Votre Choix :");
- choix = Console.saisir_entier();
- switch (choix) {
- case 1:
- this.saisir();
- break;
- case 2:
- this.afficher();
- break;
- case 3:
- this.ajouter_employe();
- break;
- case 4:
- this.ajouter_cadre();
- break;
- case 5:
- this.lister();
- break;
- case 6:
- this.supprimer();
- break;
- case 7:
- System.out.println("XML SERVICE :" + this.toXml());
- break;
- }
- } while (choix != 0);
- }
- }
Add Comment
Please, Sign In to add comment