写了个java小程序,关于设密码的,老出现构造函数出错
要求是做个密码设置程序,要求至少8位数密码,可以是数字,字母和四个特殊符号之一组成的,但是在密码设置了至少要包含2个数字和3个字母,4个特殊符号任选其一,我自己写了一个程...
要求是做个密码设置程序,要求至少8位数密码,可以是数字,字母和四个特殊符号之一组成的,但是在密码设置了至少要包含2个数字和3个字母,4个特殊符号任选其一,我自己写了一个程序,老是出现找不到构造函数。请高手帮忙看看,谢谢。
class PasswordChecker
{
int n;
char a[];
String s;
PasswordChecker(char[] x)
{
a=x;
s=new String(a);
}
boolean stringContains()
{
int count=0;
boolean b1=true,b2=true,b3=true;
if (a.length>=8)
{
for (int i=0;i<a.length ;i++ )
{
if (a[i]=='&'||a[i]=='%'||a[i]=='_'||a[i]=='!')
{
count=count+1;
}
}
if (count==1)
b1=true;
else if (count>1)
{
b1=false;
System.out.println("Ihr Passwort enthaelt zu viel Sonderzeichen");
}
else if(count==0)
{
b1=false;
System.out.println("Ihr Passwort enthaelt kein Sonderzeichen");
}
b2=true;
}
else
{
b2=false;
System.out.println("Ihr Passwort muss mindestens 8 Zeichen lang sein");
}
if (b1==true&&b2==true)
{
b3=true;
s=new String(a);
}
else
b3=false;
return b3;
}
boolean stringContainsAtLeastThreeLetters()
{
int count=0;
boolean b4;
for (int i=0;i<a.length ;i++ )
{
if (Character.isLetter(a[i])==true)
{
count=count+1;
}
}
if (count>=3)
{
b4=true;
s=new String(a);
}
else
{
b4=false;
System.out.println("Ihr Passwort muss mindestens 3 Alphabeten enthalten");
}
return b4;
}
boolean stringContainsAtLeastTwoNumbers()
{
int count=0;
boolean b5;
for (int i=0;i<a.length ;i++ )
{
if (Character.isDigit(a[i])==true)
{
count=count+1;
}
}
if (count>=2)
{
b5=true;
s=new String(a);
}
else
{
b5=false;
System.out.println("Ihr Passwort muss mindestens 2 Ziffern enthalten");
}
return b5;
}
}
class passChecker
{
public static void main(String args[])
{
boolean t1,t2,t3;
String s;
char a[];
PasswordChecker pwc;
pwc= new PasswordChecker('a','i','c','n','4','7','9','k','o');
t1=pwc.stringContains();
t2=pwc.stringContainsAtLeastThreeLetters();
t3=pwc.stringContainsAtLeastTwoNumbers();
if (t1==true&&t2==true&&t3==true)
{
s=new String(a);
System.out.println("Das Passwort "+s+" genuegt den Sicherheitskriterien");
}
}
} 展开
class PasswordChecker
{
int n;
char a[];
String s;
PasswordChecker(char[] x)
{
a=x;
s=new String(a);
}
boolean stringContains()
{
int count=0;
boolean b1=true,b2=true,b3=true;
if (a.length>=8)
{
for (int i=0;i<a.length ;i++ )
{
if (a[i]=='&'||a[i]=='%'||a[i]=='_'||a[i]=='!')
{
count=count+1;
}
}
if (count==1)
b1=true;
else if (count>1)
{
b1=false;
System.out.println("Ihr Passwort enthaelt zu viel Sonderzeichen");
}
else if(count==0)
{
b1=false;
System.out.println("Ihr Passwort enthaelt kein Sonderzeichen");
}
b2=true;
}
else
{
b2=false;
System.out.println("Ihr Passwort muss mindestens 8 Zeichen lang sein");
}
if (b1==true&&b2==true)
{
b3=true;
s=new String(a);
}
else
b3=false;
return b3;
}
boolean stringContainsAtLeastThreeLetters()
{
int count=0;
boolean b4;
for (int i=0;i<a.length ;i++ )
{
if (Character.isLetter(a[i])==true)
{
count=count+1;
}
}
if (count>=3)
{
b4=true;
s=new String(a);
}
else
{
b4=false;
System.out.println("Ihr Passwort muss mindestens 3 Alphabeten enthalten");
}
return b4;
}
boolean stringContainsAtLeastTwoNumbers()
{
int count=0;
boolean b5;
for (int i=0;i<a.length ;i++ )
{
if (Character.isDigit(a[i])==true)
{
count=count+1;
}
}
if (count>=2)
{
b5=true;
s=new String(a);
}
else
{
b5=false;
System.out.println("Ihr Passwort muss mindestens 2 Ziffern enthalten");
}
return b5;
}
}
class passChecker
{
public static void main(String args[])
{
boolean t1,t2,t3;
String s;
char a[];
PasswordChecker pwc;
pwc= new PasswordChecker('a','i','c','n','4','7','9','k','o');
t1=pwc.stringContains();
t2=pwc.stringContainsAtLeastThreeLetters();
t3=pwc.stringContainsAtLeastTwoNumbers();
if (t1==true&&t2==true&&t3==true)
{
s=new String(a);
System.out.println("Das Passwort "+s+" genuegt den Sicherheitskriterien");
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询