The CombinationLock
class models a simple rotary dial
combination lock, which is either locked or unlocked. An unlocked
CombinationLock object can be closed to lock it. A locked
CombinationLock object can be opened by turning the dial according to a
sequence of three numbers:
What variables will be needed to model this lock?
Write the CombinationLock
class with:
open
method that attempts to open the lock, and is
only successful if the correct three numbers have been enteredclose
method that sets the lock to its closed
positionThen write a CombinationLockTester
to demonstrate the
CombinationLock
class.
Some combination locks come with a combination that can't be changed, but some allow for the combination to be changed to user-defined values. To ensure security, the old values can only be changed if the lock has already been opened.
Write a CombinationLockModifiable
that has an additional
method that allows for resetting the combination to new values.