Question

In: Computer Science

Task Intro: Password JAVA and JUnit5(UNIT TESTING) Write a method that checks a password. The rules...

Task Intro: Password JAVA and JUnit5(UNIT TESTING)

Write a method that checks a password. The rules for the password are:

- The password must be at least 10 characters.
- The password can only be numbers and letters.
- Password must have at least 3 numbers.
Write a test class(Junit5/Unit testing) that tests the checkPassword method.

Hint: You can (really should) use method from built-in String class:

public boolean matches(String regex)
to check that the current string matches a regular expression. For example, if the variable "password" is the string to be checked, so will the expression.
password.matches("(?:\\D*\\d){3,}.*") 

return true if the string contains at least 3 numbers. Regular expression "^ [a-zA-Z0-9] * $" can be used to check that the password contains only numbers and letters.

Let your solution consist of 4 methods:

checkPassword(string password) [only test this method]
checkPasswordLength(string password) [checkPassword help method]
checkPasswordForAlphanumerics(string password) [checkPassword help method]
checkPasswordForDigitCount(string password) [checkPassword help method]

Intro: Password Criteria

The code is structured and formatted
Your code uses the standard java formatting and naming standard, it is also nicely formatted with the right indentation etc.
Good and descriptive variable names
Your code uses good variable names that describe the damped function, such as "counter" instead of "abc".

The code is logical and understandable

Your code is structured in a logical way so it's easy to understand what you've done and how to solve the problem. It should be easy for others to understand what your code does and how it works.

The solution shows understanding of the problem
You show with your code that you have thought about and understood the problem. It is worth thinking about how you will solve the problem before you actually solve it
The code solves the problem
Your code manages to do what is required in the assignment text, and it does not do unnecessary things either.
Unit tests (Junit5) cover all common use cases
Unit tests for your code check all common ways it can be used, such as the isEven (int number) method being tested with even, odd, negative, and null, reverseString (String text) will be checked with regular string, empty string and zero object, etc.
The code uses Regex and built-in methods
Do not try to reinvent the wheel, it is possible to check the text string for digits with a while / for loop, but using regex and matching function is much easier. There are many websites that help you find regex for what you need, so use them.

Solutions

Expert Solution



Related Solutions

Task Intro: Password JAVA. Write a method that checks a password. The rules for the password...
Task Intro: Password JAVA. Write a method that checks a password. The rules for the password are: - The password must be at least 10 characters. - The password can only be numbers and letters. - Password must have at least 3 numbers. Write a test class that tests the checkPassword method. Hint: You can (really should) use method from built-in String class: public boolean matches(String regex) to check that the current string matches a regular expression. For example, if...
Write a Java method to check whether a string is a valid password. Password rules: A...
Write a Java method to check whether a string is a valid password. Password rules: A password must have at least ten characters. A password consists of only letters and digits. A password must contain at least two digits. There are at least SIX functions/methods as the following: 1. menu() – to print the password’s rules. 2. getString() – to get the password from the user. 3. isPassword() – to check either the password is valid based on the given...
Please write a Java method contains that checks whether the second given character array is contained...
Please write a Java method contains that checks whether the second given character array is contained in the first given character array. We require that both of the arrays are partially filled.
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to...
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to enter a number of seconds. • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. • There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to...
2. Write a Java program to read a string (a password)from the user and then   check...
2. Write a Java program to read a string (a password)from the user and then   check that the password conforms to the corporate password policy.   The policy is:   1) the password must be at least 8 characters   2) the password must contain at least two upper case letters   3) the password must contain at least one digit   4) the password cannot begin with a digit   Use a for loop to step through the string.   Output “Password OK” if the password...
JAVA Write a program that checks the spelling of words in a document. This program uses...
JAVA Write a program that checks the spelling of words in a document. This program uses two text files: A dictionary file containing all known correctly spelled words, and A document to be spell-checked against the dictionary. As the document to be spell checked is read, each of its words is checked against the dictionary words. The program determines whether each word is misspelled. Misspelled words are recorded. is spelled correctly. Correctly spelled words are recorded and their frequency counted....
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine...
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine you have a rotary combination lock with many dials. Each dial has the digits 0 - 9. At any point in time, one digit from each dial is visible. Each dial can be rotated up or down. For some dial, if a 4 is currently visible then rotating the dial up would make 5 visible; rotating the dial down would make 3 visible. When...
•Write a JAVA program to check a given password strength from a user's input. •Create a...
•Write a JAVA program to check a given password strength from a user's input. •Create a method to check the number of characters. It must be more than 8. •Create a method to check the password to have at least one uppercase letter. •Create a method to check the password to have at least one lowercase letter. •Create a method to check the password to have at least one digit. •Create a method to check the password to have at...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks for a password, then asks again to confirm it. If the passwords don’t match or the rules are not fulfilled, prompt again. Your program should include a method that checks whether a password is valid. From that method, call a different method to validate the uppercase, lowercase, and digit requirements for a valid password. Your program should contain at least four methods in addition...
•Write a JAVA program to check a given password strength from a user's input. •Create a...
•Write a JAVA program to check a given password strength from a user's input. •Create a method to check the number of characters. It must be more than 8. •Create a method to check the password to have at least one uppercase letter. •Create a method to check the password to have at least one lowercase letter. •Create a method to check the password to have at least one digit. •Create a method to check the password to have at...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT