Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Description In this assignment you will create a password tester. The program will ask the user for a password and then determine if the

Assignment Description
In this assignment you will create a password tester. The program will ask the user for a password and then determine if the password meets the requirements. A valid password must adhere to the following four rules in this order:
Must be between 7 and 10 characters.
Must contain only letters and digits.
Must contain 2 and only 2 digits.
Must not be the same as the last two previous passwords.
o For this assignment, you can hard code the following as the previous passwords:
final String PREVIOUS1= "cooper11";
final String PREVIOUS2="to2mac2";
The program will allow the user 4 attempts to enter a password that meets the requirements.
After the 4th try if a valid password was not entered the program will end.
Specifications
1. Add this assignment to your project called CS1150
2. Create a Java class within that project called LastNameFirstNameAssignment7
3. Follow "CS1150 Programming Assignments Policy"
4. Write code that:
Allows the user to repeatedly enter a password up to 4 attempts.
Gracefully handles an invalid password - one that doesnt meet the 4 requirements:
o Handling an invalid password must be done in main.
o Each test method returns a boolean.
o For the password to be valid it must pass all 4 tests otherwise another loop iteration needs to occur where the user reenters the password, and the tests are run again.
o See Output examples for more details.
Step 1: Declare and initialize any constants. Declare any variables needed before the loop.
Step 2: Create a loop in main that allows the user to repeatedly enter a password.
o The loop continues while the password is invalid and 4 attempts have not occurred.
o The loop could look something like the following:
boolean passwordPassedTests = false;
while (!passwordPassedTests && numberAttempts < ATTEMPTS_ALLOWED){
// Ask user to reenter the password and perform the tests
// If all 4 tests pass, set passwordPassedTests = true
}
o The code inside the loop must:
Prompt the user to enter the password and store the password in a String.
Update the number of attempts counter.
Test the password against each rule in the order shown above.
Each password test has a method see #5 below.
If any test fails
Skip all remaining tests after that point and start the loop again
Step 3: When loop completes display a message indicting if the password meets all 4 requirements (valid) or failed the 4 requirements (invalid)
5. Design your program to use the following methods:
// Perform test to determine if passwords length is between minLength and maxLength
public static boolean lengthTest (String password, int minLength, int maxLength)
// Perform test to determine if password contains only digits and letters
public static boolean onlyLettersAndDigitsTest (String password)
// Perform test to determine if password contains only 2 digits
public static boolean containsTwoDigitsTest (String password)
// Perform test to determine if password is different than previous two passwords
public static boolean differentThanLastTwoPasswordsTest (String previousPassword1,
String previousPassword2,
String password)
// Display a specific error message based on the error codes 14:
//1- length test error
//2 only letters/digits test error
//3- only two-digits test error
//4- different than previous passwords error
// Requires using a switch statement
public static void printErrorMessage (int errorCode)
Must Do and Tips
Must Do: In your design notebook, you must include pseudocode for main and these 2 methods:
onlyLettersAndDigitsTest
containsTwoDigitsTest
Must Do: Use constants for the different errors:
There are several constants that can be created for this assignment.
At a minimum, you must create constants for each error, for example:
final int LENGTH_ERROR =1;
Must Do: Create each method as defined in assignment sheet.
Create the methods as defined in step 5 with the given return type and parameters.
You can add more methods, but you must write all the methods in step 5 as shown.
Do not change the return types or parameters of these methods.
These methods but all be used in your solution to perform the different tests.
Must Do: Call printErrorMessage only in main.
The printErrorMessage method is the only place in the code where the test results are displayed.
The method should only be called in main.
The method must use a switch statement.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Ensure continued excellence in people management.

Answered: 1 week ago

Question

Enhance the international team by recruiting the best people.

Answered: 1 week ago