-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBit.java
More file actions
68 lines (55 loc) · 1.08 KB
/
Copy pathBit.java
File metadata and controls
68 lines (55 loc) · 1.08 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
59
60
61
62
63
64
65
66
67
68
package ObjectGoPath;
public class Bit {
private int maxNum;
private int currentNumber;
private Bit nextBit;
public Bit(){
}
public Bit(Integer maxNum) {
this.maxNum = maxNum;
currentNumber = 0;
nextBit = new EmptyBit();
}
public void setNextBit(Bit nextBit) {
this.nextBit = nextBit;
}
public boolean plus() {
currentNumber++;
return checkCarry();
}
private boolean checkCarry() {
if (outOfBound()) {
return carryNextBit();
}
return true;
}
private boolean carryNextBit() {
if (!(nextBit.isNull())) {
currentNumber = 0;
return nextBit.plus();
}else {
currentNumber--;
return false;
}
}
private boolean outOfBound() {
if (currentNumber == maxNum) {
return true;
} else {
return false;
}
}
public boolean isNull() {
return false;
}
private String getCurrentNumber() {
if (nextBit.isNull()) {
return String.format("%d", currentNumber);
}else {
return String.format("%s %d", nextBit.getCurrentNumber(), currentNumber);
}
}
public void print() {
System.out.println(getCurrentNumber());
}
}