Write a class PinLock and a public class PinLockApp. A lock has a private PIN, a count of failed attempts and an open/closed state. No method ever returns the PIN.
| method | behaviour |
|---|---|
boolean unlock(String code) |
opens with the right code and resets the failures; a wrong code counts one failure; after MAX_ATTEMPTS = 3 failures the lock is blocked and refuses everything |
void lock() |
closes the lock |
boolean changePin(String newPin) |
only while open, and only for exactly 4 digits |
isOpen(), isBlocked(), attemptsLeft() |
queries |
toString() |
OPEN, BLOCKED or LOCKED (2 attempts left) |
main reads the initial PIN, then commands try CODE, lock, change CODE until the end of input.
For the input
1234 try 1111 try 1234 change 99 change 4321 lock try 1234 try 4321
the program prints
try 1111: refused -> LOCKED (2 attempts left)
try 1234: opened -> OPEN
change 99: refused -> OPEN
change 4321: done -> OPEN
lock -> LOCKED (3 attempts left)
try 1234: refused -> LOCKED (2 attempts left)
try 4321: opened -> OPEN