Answered You can hire a professional tutor to get the answer.

QUESTION

4 DoorLock Create an implementation for the class DoorLock described below. declare an integer constant, calledMAX_NUMBER_OF_ATTEMPTS, that you will...

4 DoorLock

Create an implementation for the class DoorLock described below.

  1. declare an integer constant, calledMAX_NUMBER_OF_ATTEMPTS, that you will initialize to the value 3;
  2. instance variables. The classDoorLockmust have the necessary instance variables toi)store an object of the classCombination,ii)to represent the property of being opened or closed,iii)to represent its activation state (the door lock is activated or deactivated), andiv)to count the number of unsuccessful attempts at opening the door;
  3. the class has a single constructor,DoorLock( Combination combination ), which initializes this instance with a combination. When a door lock is first created, the door lock is closed. Also, when the object is first created, it is activated and the number of failed attempts at opening it should be zero;
  4. implement the instance methodpublic boolean isOpen()that returnstrueif this door lock is currently opened andfalseotherwise;
  5. implement the instance methodpublic boolean isActivated()that returnstrueif this door lock is currently activated andfalseotherwise.
  6. implement the instance methodpublic void activate( Combination c )that sets the instance variable “activated” totrueif the parametercis “equals” to the combination of this object;
  7. finally, implement the instance methodpublic boolean open( Combination combination )such thati)an attempt is made at opening this door lock only if this door lock is activated,ii)if the parameter combination is “equals” to the combination of this door lock, set the state of the door to be open, and the number of failed attempts should be reset to zero,ii)otherwise, i.e. if the wrongCombinationwas supplied, the number of failed attempts should be incremented by one,iii)if the number of failed attempts reachesMAX_NUMBER_OF_ATTEMPTS, this door lock should be deactivated.

Hint: my implementation is approximately 40 lines long, not counting the blank lines.

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question