Solution in java ONLY plz... FULL question can be found on the following link http://ntci.on.ca/compsci/java/ch6/6_10.html ---> question 7
I cannot put full question here as its too long... so full question is on the link
The requirement is for it to NOT be done with import java.io.*; etc..... just directly
Thanks, appreciate it
----------------------------------------------------------------------------------
Write a class Lock that could be used to create electronic lock objects. Each lock may be in either an open (unlocked) or a closed (locked) state and each one is protected by its own integer key which must be used to unlock it. The class should contain the following methods.
public class Lock {
private int key;
private boolean open;
private int failedAttempts;
public Lock(int key) {
this.key = key;
open = true;
}
public void close() {
open = false;
}
public boolean isOpen() {
return open;
}
public void open(int key) {
if (!open) {
if (this.key == key) {
open = true;
failedAttempts = 0;
} else if (++failedAttempts >= 3) {
System.out.println("ALARM");
}
}
}
}
Comments
Leave a comment