Question: 1 4 . 5 . 1 : Implement a class that simulates a lock with numerical buttons. 5 4 1 6 6 6 . 3

14.5.1: Implement a class that simulates a lock with numerical buttons.
541666.3586714.qx3zqy7
Implement a class Lock that simulates a lock with numerical buttons.
Image of a touch tone phone keypad with numbers 1 to 9 and star, 0, and pound
The push method simulates the push of a numeric button with value 0 to 9.
The open method simulates the push of the key that causes the lock to open, provided that the right combination was entered. (For now, the configuration is hardwired as 1729. You will see in another section how to change it.)
As the data representation, use an integer containing the digits that have been entered up to this point. You will need to figure out how to update that number. For example, if the user had previously pushed 1 and 7, causing input to be 17, and now pushes 9, how can you set input to 179?
In the open method, return true if the lock would have been opened, false otherwise. Clicking that button resets the entered keys, whether or not the correct combination has been entered.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!