Class DigitalLock

java.lang.Object
  |
  +--DigitalLock

public class DigitalLock
extends java.lang.Object

A lock with a three digit combination. This class is derived from the example in Nino and Hosch, chapter 6. These locks are created in the open state. They can be closed, then reopened by providing the right combination of digits. Also, these locks are welded closed after certain errors. Once a lock is welded, no entry will match the combination and the lock stays closed forever.


Constructor Summary
DigitalLock(int theCombination)
          Create a lock with the given three digit combination.
 
Method Summary
 void close()
          Close this lock.
 void enter(int digit)
          Enter a digit of the combination.
 boolean isOpen()
          Get the state of the lock.
 void resetCombination(int oldC, int newC)
          Reset the combination of this lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DigitalLock

public DigitalLock(int theCombination)
Create a lock with the given three digit combination. The lock is in the open state after it is created unless an invalid combination setting is supplied in which case the lock is welded closed and can never be opened. Combination values < 100 are assumed to have leading zeros.

Parameters:
theCombination - the combination value for this lock. The digit in the 100's position is considered to be the first digit of the combination, the 10's position is the second digit, and the units position is the third digit. This value must be >=0 and <=999. If it is not, then the lock is welded closed.
Method Detail

enter

public void enter(int digit)
Enter a digit of the combination. The lock is opened if the three digits of the combination are entered in order.

Parameters:
digit - the single digit entry. Must be a single decimal digit 0-9.

isOpen

public boolean isOpen()
Get the state of the lock.

Returns:
true if the lock is open, false if the lock is closed.

close

public void close()
Close this lock. Any partially entered combination is cleared.


resetCombination

public void resetCombination(int oldC,
                             int newC)
Reset the combination of this lock. The caller must supply the correct value for the previous combination in order for this to work. Limitations on the validity of the new combination are described in the constructor. Any partially entered combination is cleared if the combination is reset.

Parameters:
oldC - the existing combination
newC - the new combination