Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, please help me create this JAVA program. It is in Chapter 6 of the Introduct

ID: 3910477 • Letter: H

Question

Hi, please help me create this JAVA program. It is in Chapter 6 of the Introduction to JAVA textbook.

Some Websites impose certain rules for passwords. Write a method that checks whether a string is a valid password.

Suppose the password rules are as follows: A password must have at least 8 characters. A password must contain only letters and digits. A password must contain at least one digits. A password must have one alphabetic character. A password must have one special character (may limit to a couple).

Explanation / Answer

public static boolean checkPassword(String password)
{
int digitCount=0,alphabetCount=0,specialChar=0;
if(password.length()<8) return false;
for(int i=0;i<password.length();i++)
{
char ch=password.charAt(i);
if(!Character.isLetter(ch) && !Character.isDigit(ch) && !Character.isSpace(ch))
++specialChar;
else if(Character.isLetter(ch))
++alphabetCount;
else if(Character.isDigit(ch))
++digitCount;
}
if(specialChar==1 && digitCount>=1 && alphabetCount==1)
return true;
else
return false;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote