inteligentny dom
· 2.5 KiB · Text
Ham
public abstract class Device {
private boolean ison;
public INHOMELOC room;
protected Device() {
}
public void turn_off(){
ison=false;
System.out.println("Je vypnute zariadenie");
}
public void turn_on(){
ison=true;
System.out.println("Je vypnute zariadenie");
}
public Device(INHOMELOC room) {
this.room = room;
}
public boolean isIson() {
return ison;
}
public void setIson(boolean ison) {
this.ison = ison;
}
public void setLocation(INHOMELOC room) {
// Code to set the location of the device
}
}
public class Dom {
private int pocetzariadeni;
private Device[] zariadenia;
public Dom() {
this.zariadenia=new Device[10];
this.pocetzariadeni=0;
}
public void addDevice(Device tentoDevice){
zariadenia[pocetzariadeni]=tentoDevice;
pocetzariadeni++;
}
public void delteDevice(Device tentoDevice){
for (int i = 0; i < pocetzariadeni; i++) {
if (zariadenia[i] == tentoDevice) {
for (int j = i; j < pocetzariadeni - 1; j++) {
zariadenia[j] = zariadenia[j + 1];
}
zariadenia[pocetzariadeni - 1] = null;
pocetzariadeni--;
break;
}
}
}
}
public class Light extends Device implements shineable,Switchable{
public Light(INHOMELOC room) {
setLocation(room);
}
@Override
public void switch_device() {
if (isIson()==false){
setIson(true);
}else{
setIson(false);
}
}
@Override
public void shine() {
System.out.println("Svietim");
}
}
public class Rekuperacia extends Device implements Switchable {
private static Rekuperacia instance;
public static Rekuperacia getInstance() {
if (instance == null) {
instance= new Rekuperacia();
}
return instance;
} //Signleton
@Override
public void switch_device() {
}
public Rekuperacia() {
setLocation(INHOMELOC.TECHNICKA);
System.out.println("Je v technickej miestnsoti");
}
}
import java.lang.reflect.Type;
import java.util.List;
public class ControlPanel <Type extends Switchable> {
private List<Type> devices;
public ControlPanel(List<Type> devices) {
this.devices = devices;
}
public void switchAll() {
for (Type device : devices) {
device.switch_device();
}
}
}
| 1 | public 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 | |
| 35 | public 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 | |
| 63 | public 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 | |
| 88 | public 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 | |
| 112 | import java.lang.reflect.Type; |
| 113 | import java.util.List; |
| 114 | |
| 115 | public 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 |