import javax.swing.*;//<----import public class Password { public static void ma
ID: 3623583 • Letter: I
Question
import javax.swing.*;//<----importpublic class Password
{ public static void main(String[] args)
{
String input,input2; //<--------------------------------------String
boolean good;//<-----------------------------------------------Boolean
input = JOptionPane.showInputDialog("Enter a password.");
good=PasswordChecker.isGood(input);
while(!good)//<---------------------------------------
{ JOptionPane.showMessageDialog(null,"Invalid password try again.");//<-----Message in dialog box
input = JOptionPane.showInputDialog("Enter a password.");
good=PasswordChecker.isGood(input);
}
JOptionPane.showMessageDialog(null,"Good password.");
input2=JOptionPane.showInputDialog("Please re enter your password.");
while(!(input2.compareTo(input)==0))//<-------------------------------------Input Messages and directions
{ JOptionPane.showMessageDialog(null,"Your passwords do not match please try again");
input2 = JOptionPane.showInputDialog("Please renter password");
}
}
}//<-----------------end of program.
//<---------------Please compile before you run this project.
Explanation / Answer
please rate - thanks
it works fine
you forgot PasswordChecker
in another file you need
public class PasswordChecker
{ public static boolean isGood(String s)
{if (s.length()>=6&&s.length()<=10 && upper(s)&&lower(s)&&number(s))
return true;
else
return false;
}
private static boolean upper(String s)
{int i;
for(i=0;i<s.length();i++)
if (Character.isUpperCase(s.charAt(i)))
return true;
return false;
}
private static boolean lower(String s)
{int i;
for(i=0;i<s.length();i++)
if (Character.isLowerCase(s.charAt(i)))
return true;
return false;
}
private static boolean number(String s)
{int i;
for(i=0;i<s.length();i++)
if (Character.isDigit(s.charAt(i)))
return true;
return false;
}
}
compile separately and then run password. it needs the PasswordChecker class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.