Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribedimage text in transcribed

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 i. store an object of the class Combination ii. to represent the property of being opened or closed iii. 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 Lock( 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 is Open() 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. = 3; public class Door Lock { // Constant. public static final int MAX_NUMBER_OF_ATTEMPTS // Instance variables. private Combination combination; private boolean open; private boolean activated; private int numberOfAttempts; // Constructor public Door Lock( Combination combination ) { // Your code here } 1/ 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 () { // Put your code here, then remove this comment. } }

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

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

=+j Describe an effective crisis management program.

Answered: 1 week ago