按照以下 UML 图中的说明设计一个名为 Password2 的类:
- 密码必须至少包含七个字符
- 密码仅由字母和数字组成
- 密码必须至少包含三位数字
+Password2 (ps: String)
输入密码的构造
+verifyPassword2():void
调用其他支持方法
-verifyLength():boolean
根据密码长度返回真/假
-verifyValidCharacters():boolean
根据有效/无效字符返回真/假
-verifyNumberOfDigits(): boolean
根据位数返回真/假
+printReport():void
打印如下指定的摘要报告
这是我到目前为止所拥有的:
public class Password2 {
private boolean rule1;
private boolean rule2;
private boolean rule3;
private String ps;
public Password2(){
}
public Password2(String ps){
this.ps = ps;
}
public void verifyPassword2(){
//Verify the password is the right length
rule1 = verifyLength();
rule2 = verifyValidCharacters();
rule3 = verifyNumberOfDigits();
}
private boolean verifyLength(){
if (ps.length() >= 8){
return true;
return false;
}
//Verify if the password have the right characters
private boolean verifyValidCharacters(){
if (ps.matches("^[A-Za-z1-9]$"){
return true;}
return false;
}
//Verify if the password contains at least 2 digits
private boolean verifyNumberOfDigits(){
int digit = 0;
for (int i = 0; i = <ps.length(); i++){
char letter = password.charAt(i);
if(Character.isDigit(letter)){
digit++;
}
if (digits >= 2){
return true;{
}
return false
}
}
public void printReport(){
String Report;
Report = "\t+++++++++++++++++ Password Report ++++++++++++++++++++\n";
Report += "\tLebron Broadnax\n";
Report += "\tCS1302\n";
Report += "\t6/11/201\n3";
Report += "\t+++++++++++++++++++++++++++++++++++++++++++++++++++++";
}
}
方法不在其他方法中这就是我发布的方式