Often the IT department or a Web site imposes certain restrictions on what can b
ID: 3640661 • Letter: O
Question
Often the IT department or a Web site imposes certain restrictions on what can be a password.Assume the following rules for passwords:
• A password must be at least six characters long
• A password may contain only letters and digits
• A password must contain at least two digits
Add a method to the Sentence class called isPassword which returns true if this Sentence is a valid password. Otherwise it returns false. Do not remove the isPalindrome method. You are enhancing the class. You want to add new functionality but leave all the ole functionality alone.
The header for the method is:
public boolean isPassword()
Notice that the method does not take a parameter.
Now write a test application that prompts the user to enter a possible password and displays "Valid Password" if the rules are followed or "Invalid Password" otherwise. Test the application thoroughly.
Explanation / Answer
Following program has a isPassword method and isPalindrome method , main program is written in the same class to test the program. tested and works as per requirement. On need same program can be extended. Please rate. package passwordvalidity; import java.io.BufferedReader; import java.io.InputStreamReader; public class Sentence { String password; public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } boolean isPassword() { int count = 0; String password = this.getPassword(); if (password.length() < 6) return false; for (int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.