From a58fbf95a7b22c9512836657fc2a89f92c6b3963 Mon Sep 17 00:00:00 2001 From: JUN Date: Tue, 18 Apr 2023 16:59:57 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B3=A0=EA=B0=9D=EB=93=B1=EB=A1=9D=20?= =?UTF-8?q?=EC=8B=9C,=20=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=82=AC=ED=95=AD=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20#1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 비밀번호가 6자가 아니라면, 예외발생 - 비밀번호가 정수형이 아니라면, 예외발생 --- firstSeminarAdvancedAssignment/docs/readme.md | 4 +-- .../domain/Client.java | 28 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/firstSeminarAdvancedAssignment/docs/readme.md b/firstSeminarAdvancedAssignment/docs/readme.md index 6c766c0..1082707 100644 --- a/firstSeminarAdvancedAssignment/docs/readme.md +++ b/firstSeminarAdvancedAssignment/docs/readme.md @@ -11,8 +11,8 @@ * [ ] ⚠️ 생년월일이 'Integer(4)-Integer(2)-Integer(2)' 형식이 아니라면, 예외발생 * [ ] ⚠️ 전화번호가 'Integer(3)-Integer(4)-Integer(4)' 형식이 아니라면, 예외발생 + [X] 비밀번호 등록 - * [ ] ⚠️ 비밀번호가 6자가 아니라면, 예외발생 - * [ ] ⚠️ 비밀번호가 숫자가 아니라면, 예외발생 + * [X] ⚠️ 비밀번호가 6자가 아니라면, 예외발생 + * [X] ⚠️ 비밀번호가 정수형이 아니라면, 예외발생 - [X] 잔액 조회 기능 + [X] 계좌번호와 비밀번호 입력 시, 잔액 조회 + [X] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생 diff --git a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/domain/Client.java b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/domain/Client.java index 4d2da70..a5e75d8 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/domain/Client.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/domain/Client.java @@ -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; @@ -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; @@ -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); @@ -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;