From de2560352358ed8d238e2224e4256c1f3f1d161c Mon Sep 17 00:00:00 2001 From: JUN Date: Fri, 14 Apr 2023 22:16:58 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9E=94=EC=95=A1=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=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 | 8 ++-- ...tSeminarAdvancedAssignmentApplication.java | 5 ++- .../domain/Client.java | 14 ++++++- .../repository/ClientRepository.java | 22 +++++++++- .../service/ClientService.java | 5 +++ .../view/InputView.java | 32 ++++++++++----- .../view/OutputView.java | 40 ++++++++++++++----- .../view/TextData.java | 4 ++ 8 files changed, 101 insertions(+), 29 deletions(-) diff --git a/firstSeminarAdvancedAssignment/docs/readme.md b/firstSeminarAdvancedAssignment/docs/readme.md index 7606206..abad36f 100644 --- a/firstSeminarAdvancedAssignment/docs/readme.md +++ b/firstSeminarAdvancedAssignment/docs/readme.md @@ -9,10 +9,10 @@ * [ ] ⚠️ 계좌번호가 'Integer-Integer-Integer' 형식이 아니라면, 예외발생 + [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 e16c665..49da5cf 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/FirstSeminarAdvancedAssignmentApplication.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/FirstSeminarAdvancedAssignmentApplication.java @@ -2,13 +2,16 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import sopt.org.firstSeminarAdvancedAssignment.controller.ClientController; @SpringBootApplication public class FirstSeminarAdvancedAssignmentApplication { + private static final ClientController clientController = new ClientController(); public static void main(String[] args) { SpringApplication.run(FirstSeminarAdvancedAssignmentApplication.class, args); - + clientController.registerClient(); + clientController.getClientAccountBalance(); } } 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 cf6cb9b..dca620c 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/domain/Client.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/domain/Client.java @@ -4,7 +4,6 @@ public class Client { private String accountNumber; private String password; - private int amount; private String name; private String birth; @@ -12,7 +11,7 @@ public class Client { private String address; - public Client(String accountNumber, String password, String name, String birth, String tel, String address) { + public Client(String accountNumber, String name, String birth, String tel, String address, String password) { this.accountNumber = accountNumber; this.password = password; this.name = name; @@ -22,7 +21,18 @@ public Client(String accountNumber, String password, String name, String birth, this.amount = 0; } + public boolean checkPassword(String password) { + if (this.password.equals(password)) { + return true; + } + return false; + } + public String getAccountNumber() { return accountNumber; } + + public int getAmount() { + return 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 ccdf261..7fe62dc 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/repository/ClientRepository.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/repository/ClientRepository.java @@ -5,7 +5,7 @@ import java.util.LinkedHashMap; import java.util.Map; -import static sopt.org.firstSeminarAdvancedAssignment.view.TextData.ACCOUNT_NUMBER_DUPLICATED_ERROR_MESSAGE; +import static sopt.org.firstSeminarAdvancedAssignment.view.TextData.*; public class ClientRepository { private static final Map clientDB = new LinkedHashMap<>(); @@ -26,4 +26,24 @@ public void register(Client client) { clientDB.put(client.getAccountNumber(), client); } + + public int getAccountBalance(String clientAcountNumber, String password) { + int clientMoneyAmount = -1; + + for (String accountNumber : clientDB.keySet()) { + if (accountNumber.equals(clientAcountNumber)) { + Client clientInfo = clientDB.get(clientAcountNumber); + + if (clientInfo.checkPassword(password)) { + clientMoneyAmount = clientInfo.getAmount(); + break; + } else { + throw new IllegalArgumentException(WRONG_PASSWORD_ERROR_MESSAGE); + } + } + } + if (clientMoneyAmount == -1) throw new IllegalArgumentException(WRONG_ACCOUNT_NUMBER_ERROR_MESSAGE); + + return clientMoneyAmount; + } } 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 3f03fdc..04c7d5a 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/service/ClientService.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/service/ClientService.java @@ -10,4 +10,9 @@ public void registerClient(String accountNumber, String name, String birth, Stri Client client = new Client(accountNumber, name, birth, tel, address, password); clientRepository.register(client); } + + public int checkAccountBalance(String accountNumber, String password) { + return clientRepository.getAccountBalance(accountNumber, password); + + } } 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 ee05606..8d26192 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/InputView.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/InputView.java @@ -6,33 +6,43 @@ public class InputView { private Scanner sc = new Scanner(System.in); private final OutputView outputView = new OutputView(); - public String inputAccountNumber() { - outputView.inputAccountNumberForRegisterMessage(); + public String inputAccountNumberForClientRegister() { + outputView.printInputAccountNumberForRegisterMessage(); return inputString(); } public String inputClientName() { - outputView.inputClientNameForRegisterMessage(); + outputView.printInputClientNameMessage(); return inputString(); } - public String inputPassword() { - outputView.inputPasswordForRegisterMessage(); + public String inputPasswordForClientRegister() { + outputView.printInputPasswordForRegisterMessage(); + return inputString(); + } + + public String inputBirthForClientRegister() { + outputView.printInputBirthForRegisterMessage(); return inputString(); } - public String inputBirth() { - outputView.inputBirthForRegisterMessage(); + public String inputTelForClientRegister() { + outputView.printInputTelNumberForRegisterMessage(); return inputString(); } - public String inputTel() { - outputView.inputTelNumberForRegisterMessage(); + public String inputAddressForClientRegister() { + outputView.printInputAddressForRegisterMessage(); return inputString(); } - public String inputAddress() { - outputView.inputAddressForRegisterMessage(); + public String inputPassword() { + outputView.printInputPasswordMessage(); + return inputString(); + } + + public String inputAccountNumber() { + outputView.printInputAccountNumberMessage(); return inputString(); } 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 ce87ee8..d7d784b 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/OutputView.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/OutputView.java @@ -2,32 +2,52 @@ public class OutputView { - public final void inputClientInfoMessage() { + // 고객 등록 메세지 + public final void printInputClientInfoMessage() { System.out.println("고객 등록을 위하여, 정보를 입력해주세요."); } - public final void inputAccountNumberForRegisterMessage() { + public final void printInputAccountNumberForRegisterMessage() { System.out.println("등록하실 계좌번호를 입력해주세요. (중복불가)"); } - public final void inputClientNameForRegisterMessage() { - System.out.println("이름을 입력해주세요."); - } - - public final void inputBirthForRegisterMessage() { + public final void printInputBirthForRegisterMessage() { System.out.println("생년월일을 입력해주세요. (2000-01-01 형식)"); } - public final void inputTelNumberForRegisterMessage() { + public final void printInputTelNumberForRegisterMessage() { System.out.println("전화번호를 입력해주세요. (010-1234-1234 형식)"); } - public final void inputAddressForRegisterMessage() { + public final void printInputAddressForRegisterMessage() { System.out.println("거주지 주소를 입력해주세요."); } - public final void inputPasswordForRegisterMessage() { + public final void printInputPasswordForRegisterMessage() { System.out.println("사용하실 비밀번호를 입력해주세요."); } + + //잔액 조회 메세지 + public final void printCheckAccountBalanceMessage() { + System.out.println("잔액 조회를 위해 계좌번호와 비밀번호를 입력해주세요."); + } + + public final void printClientAmountBalance(int amount) { + System.out.println("해당 계좌의 잔액은 " + amount + "원 입니다."); + } + + //기본 메세지 + public final void printInputClientNameMessage() { + System.out.println("이름을 입력해주세요."); + } + + public final void printInputAccountNumberMessage() { + System.out.println("계좌번호를 입력해주세요."); + } + + public final void printInputPasswordMessage() { + System.out.println("비밀번호를 입력해주세요."); + } + } diff --git a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/TextData.java b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/TextData.java index a642a92..fb86142 100644 --- a/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/TextData.java +++ b/firstSeminarAdvancedAssignment/src/main/java/sopt/org/firstSeminarAdvancedAssignment/view/TextData.java @@ -3,4 +3,8 @@ public class TextData { public static final String ACCOUNT_NUMBER_DUPLICATED_ERROR_MESSAGE = "이미 존재하는 계좌번호입니다. 다른 번호를 사용해주세요."; + + public static final String WRONG_PASSWORD_ERROR_MESSAGE = "비밀번호가 틀렸습니다. 다시 시도해주세요."; + public static final String WRONG_ACCOUNT_NUMBER_ERROR_MESSAGE = "존재하지 않는 계좌번호입니다. 다시 시도해주세요."; + }