Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java please! The code that needs to be completed is given below public class DoorLock { // Constant. public static final int MAX_NUMBER_OF_ATTEMPTS =

In java please! The code that needs to be completed is given belowimage text in transcribed

public class DoorLock { // Constant. public static final int MAX_NUMBER_OF_ATTEMPTS = 3; // Instance variables. private Combination combination; private boolean open; private boolean activated; private int numberOfAttempts; // Constructor. public DoorLock( Combination combination ) { // Your code here } // Access methods. public boolean isOpen() { return open; } public boolean isActivated() { return activated; } // Notice that numberOfAttempts is compared to // MAX_NUMBER_OF_ATTEMPTS only when its value has been // incremented, Also, numberOfAttempts should be set to zero when // activated is false. Problems related to the combined action of // these two variables have caused problems for some students. public boolean open( Combination combination ) { // Put your code here, then remove the line below. return true; } public void activate( Combination c ) { // Put your code here, then remove this comment. } }
4. Door Lock You will hand in this exercise. Download and complete the starter file here: Door Lock.java. Create an implementation for the class Door Lock described below. 1. declare an integer constant, called MAX_NUMBER_OF_ATTEMPTS, that you will initialize to the value 3: 2. instance variables. The class Door Lock must have the necessary instance variables to 1. store an object of the class Combination ii. to represent the property of being opened or closed ili. to represent its activation state (the door lock is activated or deactivated), and iv. to count the number of unsuccessful attempts at opening the door 3. the class has a single constructor, Door Locki 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 method public boolean isOpen() that returns true if this door lock is currently opened and false otherwise; 5. implement the instance method public boolean IsActivated() that returns true if this door lock is currently activated and false otherwise; 6. implement the instance method public void activate(Combination c) that sets the instance variable "activated to true if the parameter c equals to the combination of this object; 7 finally, implement the instance method public boolean open( Combination combination such that I. an attempt is made at opening this door lock only if this door lock is activated ii. if the parameter combination "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 iii. otherwise, i.e. if the wrong Combination was supplied, the number of failed attempts should be incremented by one, iv. if the number of failed attempts reaches MAX_NUMBER_OF_ATTEMPTS, this door lock should be deactivated Hint: my implementation is approximately 40 lines long, not counting the blank lines

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions