Question: You are to write java code called NumericKeypad class. The way this keypad should work is that when it is created, it will have two

You are to write java code called NumericKeypad class. The way this keypad should work is that when it is created, it will have two 4 digit codes that are stored as Strings and a boolean variable that keeps track of the locks status (locked or unlocked). The first code is the unlock code. The second code is the administrative code that must be entered when changing the unlock code. When the pad is created, both codes are set to "0000". The NumericKeypad class should have a private method that will validate the entered code to make sure that it is 4 digits (0-9).
I have provided you with the tester program. I have put comments in the program to help you understand the operation of the keypad. This class is not writen the most efficient way. In this itteration of the program all print statements are in the tester class. No printing is done from the NumericKeypad class.
below is the tester:
public class KeypadTester
{
public static void main(String[] args)
{
// Call to the constructor
NumericKeypad myKeypad = new NumericKeypad();
// Call to the setAdminCode method using a bad value. All codes must be four digits
//The first code is not four digits long
if(myKeypad.setAdminCode("000","1234"))
{
System.out.println("
The admin code has been reset.");
}
else
{
System.out.println("
*** There was a problem with the codes entered. ***");
}
// Correct call to the setAdminCode method
if(myKeypad.setAdminCode("0000","1234"))
{
System.out.println("
The admin code has been reset.");
}
else
{
System.out.println("
*** There was a problem with the codes entered. ***");
}
// Call to the resetCode method using the wrong admin code
if(myKeypad.resetCode("9876","1235"))
{
System.out.println("
The keypad code has been changed.");
}
else
{
System.out.println("
*** There was an error resetting the code. No changes made. ***");
}
// Call to the resetCode using the right admin code
if(myKeypad.resetCode("9876","1234"))
{
System.out.println("
The keypad code has been changed.");
}
else
{
System.out.println("
*** There was an error resetting the code. No changes made. ***");
}
// Call to the lock method
myKeypad.lock();
System.out.println("
The keypad is now locked.");
// Call to the unlock method using the wrong code. This is the admin code not the unlock code.
if(myKeypad.unlock("1234"))
{
System.out.println("
The keypad is now unlocked.");
}
else
{
System.out.println("
*** The incorrect code wase entered. Keypad is still locked. ***");
}
// Call to the unlock method using the right unlock code.
if(myKeypad.unlock("9876"))
{
System.out.println("
The keypad is now unlocked.");
}
else
{
System.out.println("
*** The incorrect code wase entered. Keypad is still locked. ***");
}
}
}
below is also the test case that the program will need to pass:
***Therewasaproblemwiththecodesentered.***
Theadmincodehasbeenreset.
***Therewasanerrorresettingthecode.Nochangesmade.***
Thekeypadcodehasbeenchanged.
Thekeypadisnowlocked.
***Theincorrectcodewaseentered.Keypadisstilllocked.***
Thekeypadisnowunlocked.

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 Programming Questions!