This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Combolock.java
144 lines (72 loc) · 1.84 KB
/
Combolock.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
public class Combolock
{
int dial1,dial2,dial3;
int Dial = 0;
int number1,number2,number3;
int count = 0;
public Combolock( int dial1, int dial2, int dial3 ){
this.dial1 = dial1;
this.dial2 = dial2;
this.dial3 = dial3;
}
public void reset(){
this.Dial = 0;
this.number1 = 0;
this.number2 = 0;
this.number3 = 0;
}
public void turnClockwise( int ticks )
{
if (count == 0)
{
int tempdial = this.Dial + ticks;
if (tempdial> 40)
{
this.Dial = tempdial-40;
}
else
this.Dial = tempdial;
number1 = this.Dial;
}
if (count == 2)
{
int tempdial = this.Dial + ticks;
if (tempdial > 40)
{
this.Dial = tempdial-40;
}
else
this.Dial = tempdial;
number3 = this.Dial;
}
}
public void turnCounterClockwise( int ticks )
{
if (count == 1)
{
int tempdial = this.Dial - ticks;
if (tempdial < 0)
{
this.Dial = 40+tempdial;
}
else
this.Dial = tempdial;
}
number2 = this.Dial;
}
public boolean open()
{
if(number1==dial1){
if(number2==dial2)
if(number3==dial3)
return true;
else
count=2;
else
count=1;
}
else
count=0;
return false;
}
}