forked from mufidtk/Buku---Dasar-Pemrograman-Java-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TesInterface2.java
69 lines (56 loc) · 1.77 KB
/
TesInterface2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Berkas: TesInterface2.java
interface IntLampu {
public static final int KEADAAN_HIDUP = 1;
public static final int KEADAAN_MATI = 0;
public abstract void hidupkan();
public abstract void matikan();
} // Akhir interface
interface IntLampuPenyuram extends IntLampu {
public static final int POSISI_MAKSIMUM = 10;
public static final int POSISI_MINIMUM = 0;
public abstract void redupkan();
public abstract void buatLebihTerang();
} // Akhir interface
class LampuPenyuram implements IntLampuPenyuram {
private int statusLampu = 0;
public void hidupkan() {
this.statusLampu = POSISI_MAKSIMUM;
System.out.print("hidupkan(): ");
System.out.print("lampu hidup. ");
System.out.println("Posisi tombol: " + this.statusLampu);
}
public void matikan() {
this.statusLampu = POSISI_MINIMUM;
System.out.print("matikan(): ");
System.out.println("Lampu mati ");
}
public void redupkan() {
if (this.statusLampu != POSISI_MINIMUM)
this.statusLampu--;
System.out.print("redupkan(): ");
if (this.statusLampu == POSISI_MINIMUM)
System.out.println("Lampu mati ");
else {
System.out.print("Lampu hidup. ");
System.out.println("Posisi tombol: " + this.statusLampu);
}
}
public void buatLebihTerang() {
if (this.statusLampu != POSISI_MAKSIMUM)
this.statusLampu++;
System.out.print("buatLebihTerang(): ");
System.out.print("Lampu hidup. ");
System.out.println("Posisi tombol: " + this.statusLampu);
}
} // Akhir kelas
public class TesInterface2 {
public static void main(String[] args) {
LampuPenyuram lampuKamar = new LampuPenyuram();
lampuKamar.hidupkan();
lampuKamar.redupkan();
lampuKamar.redupkan();
lampuKamar.buatLebihTerang();
lampuKamar.matikan();
lampuKamar.buatLebihTerang();
}
}