Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////// APPLIDOMOTIQUE.JAVA
- package fr.univamu.iut.exo4;
- import fr.univamu.iut.Cafetiere;
- import fr.univamu.iut.Connectable;
- import fr.univamu.iut.Demarreur;
- import fr.univamu.iut.Radio;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.List;
- public class AppliDomotique {
- public static void main(String[] args) {
- Cafetiere cafetiere = new Cafetiere();
- Radio radio = new Radio();
- List<Connectable> connectables = new ArrayList<>();
- connectables.add(radio);
- connectables.add(cafetiere);
- Demarreur demarreur = new Demarreur();
- activer(connectables, demarreur);
- demarreur.demarrerLesActives();
- }
- public static String menu() {
- String choix = "";
- System.out.println("> Faut-il demarrer cet objet ? Oui/Non");
- 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 void activer(List<Connectable> listConnectable, Demarreur demarreur){
- for (Connectable obj : listConnectable) {
- System.out.println(obj.toString());
- String type;
- type = menu();
- switch (type) {
- case "Oui":
- demarreur.attacher(obj);
- break;
- case "Non":
- break;
- }
- }
- }
- }
- ///////////////////////////////////////// DEMAREUR.JAVA
- package fr.univamu.iut;
- import java.util.ArrayList;
- import java.util.List;
- public class Demarreur {
- List<Connectable> listConnectable;
- public Demarreur(){
- this.listConnectable = new ArrayList<>();
- }
- public void demarrerLesActives(){
- for (Connectable obj : listConnectable) {
- obj.demarrer();
- }
- }
- public void attacher(Connectable obj){
- this.listConnectable.add(obj);
- }
- public void detacher(Connectable obj){
- this.listConnectable.remove(obj);
- }
- public List<Connectable> getListConnectable() {
- return listConnectable;
- }
- }
Add Comment
Please, Sign In to add comment