/* KeyPadLock1.java ** Author: R. McCloskey and < your name > ** Date: October 2019 ** ** An instance of this class models a locking device that can be either ** open or closed; to open it requires that a prescribed sequence of digits ** be entered on its keypad. */ public class KeyPadLock1 implements KeyPadLock { // class constant // -------------- protected final int MIN_CODE_LENGTH = 4; // instance variables // ------------------ protected int[] secretCode; // holds the code needed to open the lock protected int[] digitsEntered; // holds the most recently entered digits // ********************************************************** // Declaring one or more other instance variables is advised. // ********************************************************** // constructors // ------------ /* Initializes this KeyPadLock so that it is closed and so that its ** "secret code" (i.e., the sequence of digits needed to open it) ** corresponds to the contents of the given array (which is assumed ** to hold one digit per element). If the length of the given array ** is less than four, an IllegalArgumentException is thrown. */ public KeyPadLock(int[] code) { // STUB } // observers // --------- /* Reports whether or not the lock is currently open. */ public boolean isOpen() { return false; } // STUB // mutators // -------- /* Records that the given digit has been entered on the keypad. An ** IllegalArgumentException is thrown if digit is not in the range 0..9. */ public void enterDigit(int digit) { if (digit < 0 || digit > 9) { throw new IllegalArgumentException("digit must be between 0 and 9"); } // ****************** // Missing code here. // ****************** } /* If the lock is already open, it remains so. Otherwise, if the digits ** most recently entered on the keypad match the secret code, the lock ** becomes open and the memory of recently entered digits is wiped clean. ** Otherwise, the lock remains closed. */ public void open() { // STUB } /* Closes the lock, if it wasn't already. */ public void close() { // STUB } }