From 0ef309aea21e86513f9f3df0e61f69105311283c Mon Sep 17 00:00:00 2001 From: JUN Date: Sat, 15 Apr 2023 21:02:32 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9E=85=EA=B8=88=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20#1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- firstSeminarAdvancedAssignment/docs/readme.md | 6 ++-- ...tSeminarAdvancedAssignmentApplication.java | 1 + .../controller/ClientController.java | 11 +++++++ .../domain/Client.java | 5 ++++ .../repository/ClientRepository.java | 29 +++++++++++++++++-- .../service/ClientService.java | 6 ++++ .../view/InputView.java | 5 ++++ .../view/OutputView.java | 13 +++++++++ 8 files changed, 70 insertions(+), 6 deletions(-) diff --git a/firstSeminarAdvancedAssignment/docs/readme.md b/firstSeminarAdvancedAssignment/docs/readme.md index 0ac839c..9017978 100644 --- a/firstSeminarAdvancedAssignment/docs/readme.md +++ b/firstSeminarAdvancedAssignment/docs/readme.md @@ -20,9 +20,9 @@ + [X] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생 + [X] ⚠️ 잘못된 비밀번호 입력 시, 예외발생 + [X] ⚠️ 계좌 내의 금액이 출금할 금액보다 적을 시, 예외 발생 -- [ ] 입금 기능 - - [ ] 계좌번호와 입금액 입력 시, 입금 - + [ ] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생 +- [X] 입금 기능 + - [X] 계좌번호와 입금액 입력 시, 입금 + + [X] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생 - [ ] 송금 기능 - [ ] 계좌번호 / 비밀번호 / 송금할 계좌번호 / 송금할 금액 입력 시, 송금 + [ ] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생 diff --git a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/FirstSeminarAdvancedAssignmentApplication.java b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/FirstSeminarAdvancedAssignmentApplication.java index 8d0b633..d484e94 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/FirstSeminarAdvancedAssignmentApplication.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/FirstSeminarAdvancedAssignmentApplication.java @@ -12,6 +12,7 @@ public static void main(String[] args) { SpringApplication.run(FirstSeminarAdvancedAssignmentApplication.class, args); clientController.registerClient(); clientController.getClientAccountBalance(); + clientController.depositMoneyIntoAccount(); clientController.withdrawAccountBalance(); } diff --git a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/controller/ClientController.java b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/controller/ClientController.java index 83f3d15..55d7d8b 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/controller/ClientController.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/controller/ClientController.java @@ -29,4 +29,15 @@ public void withdrawAccountBalance() { outputView.printRemainAmountAfterWithdrawMessage(remainAmount); } + public void depositMoneyIntoAccount() { + outputView.printDepositIntoAccountMessage(); + + int nowAmount = clientService.depositIntoAccount(inputView.inputAccountNumber(), inputView.inputDepositMoney()); + outputView.printAmountAfterDeposit(nowAmount); + + + } + + + } 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 b439e1b..6c82625 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/domain/Client.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/domain/Client.java @@ -66,4 +66,9 @@ public int withdraw(int withdrawAmount) { this.amount -= withdrawAmount; return this.amount; } + + public int deposit(int amount) { + this.amount += amount; + return this.amount; + } } diff --git a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/repository/ClientRepository.java b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/repository/ClientRepository.java index c9689b5..ba8f728 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/repository/ClientRepository.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/repository/ClientRepository.java @@ -27,12 +27,12 @@ public void register(Client client) { clientDB.put(client.getAccountNumber(), client); } - public int getAccountBalance(String clientAcountNumber, String password) { + public int getAccountBalance(String clientAccountNumber, String password) { int clientMoneyAmount = -1; for (String accountNumber : clientDB.keySet()) { - if (accountNumber.equals(clientAcountNumber)) { - Client clientInfo = clientDB.get(clientAcountNumber); + if (accountNumber.equals(clientAccountNumber)) { + Client clientInfo = clientDB.get(clientAccountNumber); if (clientInfo.checkPassword(password)) { clientMoneyAmount = clientInfo.getAmount(); @@ -53,4 +53,27 @@ public int withdrawAccountBalance(String accountNumber, int amount) { return remainAmount; } + + public int deposit(String accountNumber, int depositAmount) { + validateIsExistAccountNumber(accountNumber); + + Client client = clientDB.get(accountNumber); + int amountAfterDeposit = client.deposit(depositAmount); + + return amountAfterDeposit; + } + + private void validateIsExistAccountNumber(String clientAccountNumber) { + boolean isAccountExist = false; + for (String accountNumber : clientDB.keySet()) { + if (accountNumber.equals(clientAccountNumber)) { + isAccountExist = true; + break; + } + } + + if(!isAccountExist) { + throw new IllegalArgumentException(WRONG_ACCOUNT_NUMBER_ERROR_MESSAGE); + } + } } diff --git a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/service/ClientService.java b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/service/ClientService.java index 4cad019..016332c 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/service/ClientService.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/service/ClientService.java @@ -26,6 +26,12 @@ public int withdrawFromClientAccount(String accountNumber, String password, int return remainAmount; } + public int depositIntoAccount(String accountNumber, int depositAmount) { + int amountAfterDeposit = clientRepository.deposit(accountNumber, depositAmount); + + return amountAfterDeposit; + } + private void validateAccountBalanceAmount(int amount, int accountBalance) { if(accountBalance < amount) { throw new IllegalArgumentException(WRONG_ACCOUNT_BALANCE_AMOUNT_ERROR_MESSAGE); diff --git a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/InputView.java b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/InputView.java index 83dab02..a5e11cf 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/InputView.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/InputView.java @@ -51,6 +51,11 @@ public int inputWithdrawAccount() { return inputInt(); } + public int inputDepositMoney() { + outputView.printDepositAmountMessage(); + return inputInt(); + } + private String inputString() { return sc.nextLine(); diff --git a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/OutputView.java b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/OutputView.java index d0fe5ba..f0fb86f 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/OutputView.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/OutputView.java @@ -51,6 +51,19 @@ public void printRemainAmountAfterWithdrawMessage(int amount) { System.out.println("출금 후 잔액은 " + amount + "원 입니다."); } + //입금 메세지 + public final void printDepositIntoAccountMessage() { + System.out.println("입금을 위해 계좌번호를 입력해주세요."); + } + + public void printDepositAmountMessage() { + System.out.println("입금하실 금액을 입력해주세요."); + } + + public void printAmountAfterDeposit(int amount) { + System.out.println("입금 후 계좌 내 금액은 " + amount + "원 입니다."); + } + //기본 메세지 public final void printInputClientNameMessage() { System.out.println("이름을 입력해주세요.");