-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathMotor.java
64 lines (61 loc) · 1.67 KB
/
Motor.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
/**
* Nama : Muhammad Rizqi Ardiansyah
* Kelas : MI 2D
* Absen : 19
* NIM : 2031710041
*/
public class Motor {
private int kecepatan = 0;
private boolean kontakOn = false;
private boolean maxKec = false;
private boolean minKec = false;
public void nyalakanMesin(){
kontakOn = true;
}
public void matikanMesin(){
kontakOn = false;
kecepatan = 0;
}
public void tambahKecepatan() {
maxKecepatan();
if (maxKec == false) {
if (kontakOn == true) {
kecepatan += 50;
} else {
System.out.println("Kecepatan tidak bisa bertambah karena"
+ " Mesin off! \n");
}
}
}
public void kurangiKecepatan() {
minKecepatan();
if (minKec == false) {
if (kontakOn == true) {
kecepatan -= 50;
} else {
System.out.println("Kecepatan tidak bisa berkurang karena"
+ " Mesin off! \n");
}
}
}
public void printStatus(){
if(kontakOn == true){
System.out.println("Kontak On");
}else{
System.out.println("Kontak Off");
}
System.out.println("Kecepatan "+kecepatan+"\n");
}
public void maxKecepatan(){
if(kecepatan >= 150){
maxKec = true;
System.out.println("Kecepatan sudah maksimal");
}
}
public void minKecepatan(){
if(kecepatan <= 0){
minKec = true;
System.out.println("Motor sudah berhenti");
}
}
}