Implement a progra Proper coding conventions required the first letter of the cl
ID: 3627198 • Letter: I
Question
Implement a prograProper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letterm that reads in a user password and verifies it meets the following criteria:
Is atleast 8 characters long
Contains atleast 1 lower letter character
Contains atleast 1 upper letter character
Contains atleast 1 numeric digit
Contains atleast 1 special character from the set: !@#$%^&*
Does not contain the word “and” or the word “end”
Output a string that prompts the user for a password and include the requirements above in your output.
Output a string that states valid or invalid. If invalid, state which rule above has not been met.
Utilize the following functionality:
· indexOf
· Looping structure
· charAt()
· isDigit()
· isUpperCase()
· isLowerCase()
· and any additional functionality needed
Explanation / Answer
please rate - thanks
import java.util.Scanner;
public class ValidPassword
{
public static void main (String[] args)
{String word;
Scanner input = new Scanner(System.in);
System.out.println("Enter your password here: ");
word=input.next();
if (len(word) && upper(word)&&lower(word)&&number(word)&&special(word)&&good(word))
System.out.println("valid password");
else
System.out.println("invalid password");
}
public static boolean len(String s)
{int i;
if(s.length()>=8)
return true;
else
System.out.println("Too few characters");
return false;
}
public static boolean upper(String s)
{int i;
for(i=0;i<s.length();i++)
if (Character.isUpperCase(s.charAt(i)))
return true;
System.out.println("No upper case");
return false;
}
public static boolean lower(String s)
{int i;
for(i=0;i<s.length();i++)
if (Character.isLowerCase(s.charAt(i)))
return true;
System.out.println("No lower case");
return false;
}
public static boolean number(String s)
{int i;
for(i=0;i<s.length();i++)
if (Character.isDigit(s.charAt(i)))
return true;
System.out.println("No digit");
return false;
}
public static boolean special(String s)
{int i,sum=0;
String specials="!@#$%^&*";
for(i=0;i<specials.length();i++)
sum+=s.indexOf(specials.charAt(i));
if(sum!=specials.length()*-1)
return true;
System.out.println("No special character");
return false;
}
public static boolean good(String s)
{if(s.indexOf("end")==-1&&s.indexOf("and")==-1)
return true;
System.out.println("contains and or end");
return false;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.