Master Engineering with Fun Quizzes & Brain Teasers!
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.