Последняя активность 1737400265

inteligentny dom Исходник
1public abstract class Device {
2 private boolean ison;
3 public INHOMELOC room;
4
5 protected Device() {
6 }
7
8 public void turn_off(){
9 ison=false;
10 System.out.println("Je vypnute zariadenie");
11 }
12
13 public void turn_on(){
14 ison=true;
15 System.out.println("Je vypnute zariadenie");
16 }
17
18 public Device(INHOMELOC room) {
19 this.room = room;
20 }
21
22 public boolean isIson() {
23 return ison;
24 }
25
26 public void setIson(boolean ison) {
27 this.ison = ison;
28 }
29 public void setLocation(INHOMELOC room) {
30 // Code to set the location of the device
31 }
32
33}
34
35public class Dom {
36 private int pocetzariadeni;
37 private Device[] zariadenia;
38
39 public Dom() {
40 this.zariadenia=new Device[10];
41 this.pocetzariadeni=0;
42
43 }
44 public void addDevice(Device tentoDevice){
45 zariadenia[pocetzariadeni]=tentoDevice;
46 pocetzariadeni++;
47 }
48 public void delteDevice(Device tentoDevice){
49 for (int i = 0; i < pocetzariadeni; i++) {
50 if (zariadenia[i] == tentoDevice) {
51 for (int j = i; j < pocetzariadeni - 1; j++) {
52 zariadenia[j] = zariadenia[j + 1];
53 }
54 zariadenia[pocetzariadeni - 1] = null;
55 pocetzariadeni--;
56 break;
57 }
58 }
59 }
60}
61
62
63public class Light extends Device implements shineable,Switchable{
64 public Light(INHOMELOC room) {
65 setLocation(room);
66
67 }
68
69
70 @Override
71 public void switch_device() {
72 if (isIson()==false){
73 setIson(true);
74 }else{
75 setIson(false);
76 }
77 }
78
79 @Override
80 public void shine() {
81 System.out.println("Svietim");
82 }
83
84
85}
86
87
88public class Rekuperacia extends Device implements Switchable {
89 private static Rekuperacia instance;
90
91 public static Rekuperacia getInstance() {
92 if (instance == null) {
93 instance= new Rekuperacia();
94 }
95 return instance;
96
97 } //Signleton
98
99 @Override
100 public void switch_device() {
101
102 }
103
104 public Rekuperacia() {
105 setLocation(INHOMELOC.TECHNICKA);
106 System.out.println("Je v technickej miestnsoti");
107
108 }
109}
110
111
112import java.lang.reflect.Type;
113import java.util.List;
114
115public class ControlPanel <Type extends Switchable> {
116 private List<Type> devices;
117
118 public ControlPanel(List<Type> devices) {
119 this.devices = devices;
120 }
121 public void switchAll() {
122 for (Type device : devices) {
123 device.switch_device();
124 }
125
126 }
127}
128