Skip to content

Commit

Permalink
feat: 입금기능 구현 #1
Browse files Browse the repository at this point in the history
  • Loading branch information
PgmJun committed Apr 15, 2023
1 parent d37ee7f commit 0ef309a
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 6 deletions.
6 changes: 3 additions & 3 deletions firstSeminarAdvancedAssignment/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
+ [X] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생
+ [X] ⚠️ 잘못된 비밀번호 입력 시, 예외발생
+ [X] ⚠️ 계좌 내의 금액이 출금할 금액보다 적을 시, 예외 발생
- [ ] 입금 기능
- [ ] 계좌번호와 입금액 입력 시, 입금
+ [ ] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생
- [X] 입금 기능
- [X] 계좌번호와 입금액 입력 시, 입금
+ [X] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생
- [ ] 송금 기능
- [ ] 계좌번호 / 비밀번호 / 송금할 계좌번호 / 송금할 금액 입력 시, 송금
+ [ ] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static void main(String[] args) {
SpringApplication.run(FirstSeminarAdvancedAssignmentApplication.class, args);
clientController.registerClient();
clientController.getClientAccountBalance();
clientController.depositMoneyIntoAccount();
clientController.withdrawAccountBalance();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);


}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public int inputWithdrawAccount() {
return inputInt();
}

public int inputDepositMoney() {
outputView.printDepositAmountMessage();
return inputInt();
}


private String inputString() {
return sc.nextLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("이름을 입력해주세요.");
Expand Down

0 comments on commit 0ef309a

Please sign in to comment.