Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.univamu.iut.exo4;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- public class AppliDomotique {
- static ArrayList<Connectable> objets = new ArrayList<Connectable>();
- static Demarreur demarreur = new Demarreur();
- public static String menu(String string) {
- String choix = " ";
- System.out.println(string);
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- try {
- choix = in.readLine();
- } catch (IOException e) {
- System.out.println("Problème de saisie");
- }
- return choix;
- }
- public static Connectable connecter(String type)throws ClassNotFoundException{
- FabriqueAbstraite fabrique = new FabriqueConcrete();
- return fabrique.fabriquer(type);
- }
- public static void activer() {
- String choix = " ";
- for(Connectable c : objets)
- {
- if(!(choix = menu("Souhaitez vous activer l'objet : " + c + " ? " +"Tapez non ou sinon l'objet sera ajouté")).equals("non")) demarreur.attacher(c);
- }
- demarreur.demarrerLesActives();
- }
- public static void désactiver() {
- String choix = " ";
- for(Connectable c : objets)
- {
- if(!(choix = menu("Souhaitez vous désactiver l'objet : " + c + " ? " +"Tapez non ou sinon l'objet sera désactivé")).equals("non")) demarreur.detacher(c);
- }
- demarreur.demarrerLesActives();
- }
- public static void main(String[] args) {
- String type = " ";
- try {
- while ((type = menu("Taper le nom de l'objet que vous voulez connecter (radiateur,cafetiere ou radio) et EOF(CTRL +D) pour terminer")) != "EOF") {
- objets.add(connecter(type));
- }
- }catch (ClassNotFoundException c){
- System.out.println("Classe inexistante");
- } catch (NullPointerException n){
- System.out.println("fichier terminé");
- }
- activer();
- désactiver();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement