Write the class Lock that could use to create electronic lock objects. Each lock may be in either an open (unlocked) or a closed (locked) state and each is protected by its own integer key which must be used to unlock it. The class should contain the following methods:

public Lock(int key)
Create a lock that initially open

public void close()
Close the lock

public boolean isOpen()
Return true if and if the lock is open

public void open(int key)
Open the lock if and only if the parameter key matches the lock’s own key. If the lock is closed and the keys do not match, count that failed attempt. If the same lock receives three (3) or more failed attempts in a row, print the message “Alarm” (this to be done in main).

Check for correct input (key can only be a 3 digit integer). User input (lock key) is expected. The following main method illustrates how the Lock class should work:

public static void main (String[] args)

  System.out.println("Enter key");
  int key1 = Integer.parseInt(obj.readLine()); // set to 111

  System.out.println("Enter key");
  int key2 = Integer.parseInt(obj.readLine()); // set to 222

  Lock lock1 = new Lock (key1);
  Lock lock2 = new Lock (key2);


  System.out.println(lock1.isOpen()); // prints false; // fails to open; // fails to open; // opens lock2; // fails - prints “Alarm”; // opens lock1