-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwheel.java
More file actions
58 lines (48 loc) · 1.29 KB
/
wheel.java
File metadata and controls
58 lines (48 loc) · 1.29 KB
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
public class Wheel {
private int capacity;
private int[] datas;
private int end;
Wheel(int capacity) {
this.capacity = capacity;
this.datas = new int[capacity];
this.end = 0;
}
public void addData(int data) {
if (isFull()) {
System.out.println("Wheel is full");
} else {
this.datas[this.end] = data;
this.end += 1;
}
}
public int getData() {
int middle = (this.capacity - 1) / 2;
return this.datas[middle];
}
public boolean isFull() {
return (this.end == this.capacity - 1);
}
public boolean isEmpty() {
return (this.end == 0);
}
public void rotateClockWise() {
this.capacity -= 2;
}
public void rotateCounterClockWise() {
this.capacity += 2;
}
}
public static void main(String[] args) {
Wheel roda = new Wheel(10);
roda.addData(5);
roda.addData(12);
roda.addData(70);
roda.addData(54);
int x = roda.getData(); // return null karena data yang ditengah wheel masih kosong
roda.addData(72);
int a = roda.getData(); // return 72
roda.rotateClockWise();
int y = roda.getData(); // return 54
roda.rotateClockWise();
int b = roda.getData(); // return 70
}