Combination Lock

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:

  1. turn the dial right until you reach the first number
  2. turn the dial left and past the second number, and continue turning until you again reach that second number
  3. turn the dial right again to stop at the third number
  4. pull up on the loop to open the lock

What variables will be needed to model this lock?

Write the CombinationLock class with:

Then write a CombinationLockTester to demonstrate the CombinationLock class.

Extension

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.