Question
Complete the following file in Java: /** A simulated lock with digit buttons. */ public class Lock { private int combination = 1729; private int
Complete the following file in Java:
/** A simulated lock with digit buttons. */ public class Lock { private int combination = 1729; private int input;
/** Simulates a digit button push. @param button a digit 0 ... 9 */ public void push(int button) { . . . } /** Simulates a push of the open button. @return true if the lock opened */ public boolean open() { . . . } }
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 had been entered.
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