Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You will hand in this exercise. Download and complete the starter file here: Combination.java. Implement a class, called Combination, to store three integer values (
You will hand in this exercise. Download and complete the starter file here: Combination.java.
Implement a class, called Combination, to store three integer values ints
declare the necessary instance variables to store the three integer values;
create a constructor, public Combinationint first, int second, int third to initialize the values of this object.
implement the instance method public boolean equalsCombination other such that equals returns true if other contains the same values, in the same order, as this Combination; the order is defined by the order of the parameters of the constructor, given the following:
Combination c c c;
c new Combination;
c new Combination;
c new Combination;
then cequalsc is true but cequalsc is false;
finally, implement the method public String toString to return a String representation of this object, where the first, second and third values are concatenated and separated by : symbols. Eg
Combination c;
c new Combination;
System.out.printlnc;
displays ::
The interface of the class Combination consists therefore of its constructor, the method equals and the method toString.
Ideally, the input data should be validated. In particular, all the values should be in the range to However, since we do not yet have the tools to handle exceptional situations, we will assume for now that all the input data are valid!
Note: Simpler code is better and it is worthwhile spending time cleaning up code even if it was already working.
Hint: my implementation is approximately lines long, not counting blank lines. This is not a contest to write the shortest class declaration. I am providing this information so that you can evaluate the relative complexity of the tasks.
DoorLock
You will hand in this exercise. Download and complete the starter file here: DoorLock.java.
Create an implementation for the class DoorLock described below.
declare an integer constant, called MAXNUMBEROFATTEMPTS, that you will initialize to the value ;
instance variables. The class DoorLock must have the necessary instance variables to
store an object of the class Combination
to represent the property of being opened or closed
to represent its activation state the door lock is activated or deactivated and
to count the number of unsuccessful attempts at opening the door;
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;
implement the instance method public boolean isOpen that returns true if this door lock is currently opened and false otherwise;
implement the instance method public boolean isActivated that returns true if this door lock is currently activated and false otherwise;
implement the instance method public void activateCombination c that sets the instance variable activated to true if the parameter c equals to the combination of this object;
finally, implement the instance method public boolean open Combination combination such that
an attempt is made at opening this door lock only if this door lock is activated
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
otherwise, ie if the wrong Combination was supplied, the number of failed attempts should be incremented by one,
if the number of failed attempts reaches MAXNUMBEROFATTEMPTS, this door lock should be deactivated.
Hint: my implementation is approximately lines long, not counting the blank lines.
SecurityAgent if there is time
Implement the class SecurityAgent described below.
instance variables. A security agent is responsible for a particular door lock. Declare the necessary instance variables such that a SecurityAgent
remembers stores a Combination and
has access to this particular DoorLock, ie maintains a reference to a DoorLock object;
implement a constructor with no parameter such that when a new SecurityAgent is created
it creates a new Combination and stores it
it creates a new DoorLock with this saved Combination. For the sake of simplicity, you may decide to always use the same combination:
Combination secret;
secret new Combination;
if secret is the name of the instance variable that is used to remember the Combination. Or you can let your SecurityAgents use their imagination, so that each SecurityAgent has a new Combination that it only knows.
int first, second, third;
first intMathrandom;
second intMathrandom;
third intMathrandom;
secret new Combinationfirst second, third;
Alternative w
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started