Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. package fr.univamu.iut.exo4;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.ArrayList;
  7.  
  8. public class AppliDomotique {
  9.     static ArrayList<Connectable> objets = new ArrayList<Connectable>();
  10.     static Demarreur demarreur = new Demarreur();
  11.  
  12.     public static String menu(String string) {
  13.         String choix = " ";
  14.         System.out.println(string);
  15.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  16.         try {
  17.             choix = in.readLine();
  18.         } catch (IOException e) {
  19.             System.out.println("Problème de saisie");
  20.         }
  21.         return choix;
  22.     }
  23.  
  24.     public static Connectable connecter(String type)throws ClassNotFoundException{
  25.         FabriqueAbstraite fabrique = new FabriqueConcrete();
  26.         return fabrique.fabriquer(type);
  27.     }
  28.  
  29.     public static void activer() {
  30.         String choix = " ";
  31.         for(Connectable c : objets)
  32.         {
  33.             if(!(choix = menu("Souhaitez vous activer l'objet : " + c + " ? " +"Tapez non ou sinon l'objet sera ajouté")).equals("non"))  demarreur.attacher(c);
  34.         }
  35.         demarreur.demarrerLesActives();
  36.  
  37.     }
  38.  
  39.     public static void désactiver() {
  40.         String choix = " ";
  41.         for(Connectable c : objets)
  42.         {
  43.             if(!(choix = menu("Souhaitez vous désactiver l'objet : " + c + " ? " +"Tapez non ou sinon l'objet sera désactivé")).equals("non"))  demarreur.detacher(c);
  44.         }
  45.         demarreur.demarrerLesActives();
  46.  
  47.     }
  48.  
  49.     public static void main(String[] args) {
  50.         String type = " ";
  51.         try {
  52.             while ((type = menu("Taper le nom de l'objet que vous voulez connecter (radiateur,cafetiere ou radio) et EOF(CTRL +D) pour terminer")) != "EOF") {
  53.                 objets.add(connecter(type));
  54.             }
  55.         }catch (ClassNotFoundException c){
  56.             System.out.println("Classe inexistante");
  57.         } catch (NullPointerException n){
  58.             System.out.println("fichier terminé");
  59.         }
  60.         activer();
  61.         désactiver();
  62.  
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement