package ac;

 * @author Saniya
 public class AC implements Control {

    private int statusAC = 0;
    private int statusSuhu = 0;

    @Override
    public void hidupkan() {
        if (this.statusAC == keadaanMati) {
            this.statusAC = keadaanHidup;
            System.out.println("Hidupkan AC! --> AC Hidup");
        } else {
            System.out.println("Hidupkan AC! --> AC Sudah Hidup Kok");
        }
    }

    @Override
    public void matikan() {

        if (this.statusAC == keadaanHidup) {
            this.statusAC = keadaanMati;
            System.out.println("Matikan AC! --> AC Mati");
        } else {
            System.out.println("Matikan AC! --> AC Sudah Mati Kok");
        }
    }



    @Override
    public void panaskan() {
        System.out.println("Rubah Suhu --> Panas");
        if (this.statusAC == keadaanMati) {
            System.out.println("AC --> Masih Mati kok dipanaskan");
        } else {
            if (this.statusAC == keadaanHidup && this.statusSuhu == tmpDingin) {
                this.statusSuhu = tmpPanas;
                System.out.println("Suhu AC! --> AC Panas");
            } else {
                System.out.println("Suhu AC! --> AC Sudah panas kok dipanaskan");
            }
        }
    }

    @Override
    public void dinginkan() {
        System.out.println("Rubah AC! --> Dingin");
        if (this.statusAC == keadaanMati) {
            System.out.println("AC --> Masih Mati kok didinginkan");
        } else {
            if (this.statusAC == keadaanHidup && this.statusSuhu == tmpPanas) {
                this.statusSuhu = tmpDingin;
                System.out.println("Suhu AC! --> AC Dingin");
            } else {
                System.out.println("Suhu AC! --> AC Sudah dingin kok didinginkan");
            }
        }
    }
}
 package ac;

 * @author Saniya

public interface Control {
    public static final int keadaanHidup = 1;
    public static final int keadaanMati = 0;
    public static final int tmpDingin = 1;
    public static final int tmpPanas = 0;
   
    public abstract void hidupkan();
    public abstract void matikan();
    public abstract void panaskan();
    public abstract void dinginkan();
}




package ac;

 * @author Saniya

public class TestControl {
    public static void main(String[] args) {
        AC ACKamar = new AC(); //inisiasi object
        System.out.println("Status AC Saat Ini: Mati");
        ACKamar.hidupkan(); //Hidupkan AC
        ACKamar.hidupkan(); //Hidupkan AC
        ACKamar.matikan(); //Matikan AC
        ACKamar.matikan(); //Matikan AC
        ACKamar.dinginkan();
        ACKamar.hidupkan(); //Hidupkan AC
        ACKamar.panaskan();
        ACKamar.dinginkan();
        ACKamar.dinginkan();
        ACKamar.panaskan();
        ACKamar.panaskan();
        ACKamar.matikan(); //Matikan AC
    }
}