GiantStepDEV

๋ฌธ์ œ

์•”ํ˜ธ์˜ ๊ธธ์ด๋Š” 10 ~ 30์ž ์‚ฌ์ด
์•”ํ˜ธ์—๋Š” ์ˆซ์ž, ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ํŠน์ˆ˜ ๋ฌธ์ž๊ฐ€ ํฌํ•จ๋˜์–ด์•ผ ํ•จ
ํŠน์ˆ˜๋ฌธ์ž๋Š” (!, %, _, #, &, +, -, *, /)์˜ 9๊ฐœ ์ค‘ ํ•˜๋‚˜
์ž…๋ ฅ ๋ฐ›์€ ํŒจ์Šค์›Œ๋“œ๊ฐ€ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋ฉด "Good password", ์•„๋‹ˆ๋ฉด "Bad password" ์ถœ๋ ฅ ๋ฐ˜๋ณต๋ฌธ์„ ์‚ฌ์šฉํ•˜๊ณ 
์‚ฌ์šฉ์ž๊ฐ€ "์ข…๋ฃŒ" ๋˜๋Š” "exit" ์ž…๋ ฅํ•˜๋ฉด ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ

* ๋ฐฐ์šด ๊ฒƒ์„ ๋ณต์Šตํ•  ๊ฒธ ์ •๊ทœ์‹์€ ์ด์šฉํ•˜์ง€ ์•Š๊ณ  ํ’€์—ˆ์Šต๋‹ˆ๋‹ค.

package ์•”ํ˜ธ์ฒดํฌ๋ฌธ์ œ;
import java.util.Scanner;

public class Password {
    String password;

    public void setPassword() {
        Scanner sc = new Scanner(System.in);
        password = sc.next();
    }

    public boolean pwLength() {
        if(password.length() >= 10 && password.length() <= 30) {
            return true;
        }
        return false;
    }

    public boolean pwOptionSmallLetter() {
        for(int i = 0; i < password.length(); i++) {
            if(password.charAt(i) >= 'a' && password.charAt(i) <= 'z') return true;
        }
        return false;
    }

    public boolean pwOptionBigLetter() {
        for(int i = 0; i < password.length(); i++) {
            if(password.charAt(i) >= 'A' && password.charAt(i) <= 'Z') return true;
        }
        return false;
    }

    public boolean pwOptionNum() {
        for(int i = 0; i < password.length(); i++) {
            if(password.charAt(i) >= '0' && password.charAt(i) <= '9') return true;
        }
        return false;
    }

    public boolean pwOptionSpeChar() {
        String specialLetter = "!%_&#+-*/";
        for(int i = 0; i < specialLetter.length(); i++) {
            for(int j = 0; j < password.length(); j++) {
                if(specialLetter.charAt(i) == password.charAt(j)) return true;
            }
        }
        return false;
    }

    public void getPassword() {
        if(pwLength() && pwOptionSmallLetter() && pwOptionBigLetter() && pwOptionSpeChar() && pwOptionNum()) {
            System.out.println("Good password");
        }
        else System.out.println("Bad password");
    }

    public void confirmPw() {
        while(true) {
            setPassword();
            pwLength();
            pwOptionSpeChar();
            pwOptionNum();
            pwOptionBigLetter();
            pwOptionSmallLetter();
            if(password.equals("์ข…๋ฃŒ") || password.equals("exit")) return;
            getPassword();
        }
    }
}
package ์•”ํ˜ธ์ฒดํฌ๋ฌธ์ œ;

public class PwdCheckMain {
    public static void main(String[] args) {
        Password password = new Password();
        password.confirmPw();
    }
}
profile

GiantStepDEV

@kongmi

ํฌ์ŠคํŒ…์ด ์ข‹์•˜๋‹ค๋ฉด "์ข‹์•„์š”โค๏ธ" ๋˜๋Š” "๊ตฌ๋…๐Ÿ‘๐Ÿป" ํ•ด์ฃผ์„ธ์š”!