-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathOverloadedCounterClass.java
63 lines (52 loc) · 1.23 KB
/
OverloadedCounterClass.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
/**
*
* @author giuseppedesantis
*/
public class Counter {
private int value;
private boolean check;
public Counter(int StartingValue, boolean check){
this.value = StartingValue;
this.check = check;
}
public Counter(int StartingValue){
this(StartingValue, false);
}
public Counter(boolean check){
this(0, true);
}
public Counter(){
this(0, false);
}
public int value(){
return this.value;
}
public void increase(){
this.value++;
}
public void decrease(){
if(this.check == true){
if(this.value >= 1){
this.value--;
}
} else if(this.check == false){
this.value--;
}
}
public void increase(int by){
if(by >= 0){
this.value += by;
}
}
public void decrease(int by){
if(by > 0){
if(this.check == true && by <= this.value){
this.value -= by;
}else if(this.check == true && by > this.value){
this.value = 0;
}else if(this.check == false){
this.value -= by;
}
}
}
}