Skip to content

Commit

Permalink
feat: 고객등록 시, 비밀번호 예외처리 사항 구현 #1
Browse files Browse the repository at this point in the history
- 비밀번호가 6자가 아니라면, 예외발생
- 비밀번호가 정수형이 아니라면, 예외발생
  • Loading branch information
PgmJun committed Apr 18, 2023
1 parent 6f2b85e commit a58fbf9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions firstSeminarAdvancedAssignment/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* [ ] ⚠️ 생년월일이 'Integer(4)-Integer(2)-Integer(2)' 형식이 아니라면, 예외발생
* [ ] ⚠️ 전화번호가 'Integer(3)-Integer(4)-Integer(4)' 형식이 아니라면, 예외발생
+ [X] 비밀번호 등록
* [ ] ⚠️ 비밀번호가 6자가 아니라면, 예외발생
* [ ] ⚠️ 비밀번호가 숫자가 아니라면, 예외발생
* [X] ⚠️ 비밀번호가 6자가 아니라면, 예외발생
* [X] ⚠️ 비밀번호가 정수형이 아니라면, 예외발생
- [X] 잔액 조회 기능
+ [X] 계좌번호와 비밀번호 입력 시, 잔액 조회
+ [X] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public class Client {


public Client(String accountNumber, String name, String birth, String tel, String address, String password) {
validateAccountNumber(accountNumber);
validateAccountNumberForRegister(accountNumber);
this.accountNumber = accountNumber;
validatePasswordForRegister(password);
this.password = password;
this.name = name;
this.birth = birth;
Expand All @@ -24,6 +25,7 @@ public Client(String accountNumber, String name, String birth, String tel, Strin
this.amount = 0;
}


public boolean checkPassword(String password) {
if (this.password.equals(password)) {
return true;
Expand All @@ -39,7 +41,9 @@ public int getAmount() {
return amount;
}

private void validateAccountNumber(String accountNumber) {


private void validateAccountNumberForRegister(String accountNumber) {
String[] seperatedAccountNumber = accountNumber.split("-");

validateAccountNumberLength(seperatedAccountNumber);
Expand All @@ -62,6 +66,26 @@ private void validateAccountNumberLength(String[] seperatedAccountNumber) {
}
}

private void validatePasswordForRegister(String password) {
validatePasswordNumberFormat(password);
validatePasswordNumberLength(password);
}

private void validatePasswordNumberLength(String password) {
if(password.length() != 6) {
throw new IllegalArgumentException(createErrorMessage("비밀번호는 6자로 구성되어야합니다."));
}
}

private void validatePasswordNumberFormat(String password) {
try {
Integer.parseInt(password);
}catch (NumberFormatException e) {
throw new IllegalArgumentException(createErrorMessage("비밀번호는 정수형으로 구성되어야합니다."));
}
}


public int transfer(int transferAmount) {
validateAccountBalanceToTransfer(transferAmount);
this.amount -= transferAmount;
Expand Down

0 comments on commit a58fbf9

Please sign in to comment.