設計了一個名爲密碼2如下面的UML圖指定類: 上午我做這些布爾方法正確
- 密碼必須至少有七個字符
- 密碼只由字母和數字
- 密碼必須包含至少三個數字
+Password2 (ps: String)
個構造帶密碼進入
+verifyPassword2():void
調用其他配套方法
-verifyLength():boolean
返回真/假基於密碼的長度
-verifyValidCharacters():boolean
返回真/假基於有效/無效字符
-verifyNumberOfDigits(): boolean
返回true/false基於位數
+printReport():void
打印總結報告爲特殊cified下面
這是我到目前爲止有:
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+++++++++++++++++++++++++++++++++++++++++++++++++++++";
}
}
方法不是另一種方法裏面這只是我怎麼貼吧
代碼審查問題應該在[專用網站](http://codereview.stackexchange.com)上。 – fge
你不能在一個方法內創建一個方法,這個代碼根本不會編譯。前往審查網站,或者說明你的問題。 –
你的'if(...)return ...'應該有'else'。實際上你確實需要它們,只是返回布爾表達式本身。 –