Skip to content

Commit

Permalink
feat: 잔액 조회 기능 구현 #1
Browse files Browse the repository at this point in the history
  • Loading branch information
PgmJun committed Apr 14, 2023
1 parent baa93a6 commit de25603
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 29 deletions.
8 changes: 4 additions & 4 deletions firstSeminarAdvancedAssignment/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* [ ] ⚠️ 계좌번호가 'Integer-Integer-Integer' 형식이 아니라면, 예외발생
+ [X] 개인정보 등록(이름,생년월일,전화번호,주소)
+ [X] 비밀번호 등록
- [ ] 잔액 조회 기능
+ [ ] 계좌번호와 비밀번호 입력 시, 잔액 조회
+ [ ] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생
+ [ ] ⚠️ 잘못된 비밀번호 입력 시, 예외발생
- [X] 잔액 조회 기능
+ [X] 계좌번호와 비밀번호 입력 시, 잔액 조회
+ [X] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생
+ [X] ⚠️ 잘못된 비밀번호 입력 시, 예외발생
- [ ] 출금 기능
- [ ] 계좌번호와 비밀번호와 출금할 금액 입력 시, 출금
+ [ ] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ public class Client {

private String accountNumber;
private String password;

private int amount;
private String name;
private String birth;
private String tel;
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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Client> clientDB = new LinkedHashMap<>();
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("비밀번호를 입력해주세요.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "존재하지 않는 계좌번호입니다. 다시 시도해주세요.";

}

0 comments on commit de25603

Please sign in to comment.