음.....어제 한거 설명하고 오늘 하나 내주고 끝이라니....
전체 3개의 클래스로 구성된다
1. BankMain Class
2. BankDTO Class
- 고객번호(clientNumber), 이름(name), 계좌번호(accountNumber), 잔액(balance)
3. BankService Class
- 고객등록, 전체고객조회, 입금, 출금, 잔액확인
주요기능
1. while문을 이용하여 각 기능을 선택하도록 한다.
고객등록 (clientJoin)
1) 고객등록시 이름, 계좌번호를 입력받는다.
a. 계좌번호는 임의로 입력한다.
2) 고객번호는 자동으로 부여된다.
a. 예를들어 현재 회원이 3명이라면 신규회원의 회원번호는 4가 되어야 함.
b. 회원이 아무도 없을 때는 1번이 되어야 함.
3) 잔액은 기본 0원으로 함.
전체 고객조회 (clientListView)
1) 등록된 전체 고객 목록을 출력함.
입금 (deposit)
1) 이름과 계좌번호를 스캐너를 이용하여 입력받고 두 정보 모두 일치하면 입금할 금액을 입력받고 입력기능 처리
2) 일치하지 않으면 '정보가 틀립니다.' 출력
출금 (withdraw)
1) 이름과 계좌번호를 스캐너를 이용하여 입력받고 두 정보 모두 일치하면 출금할 금액을 입력 받음
2) 출금 금액이 잔액보다 크면 출금불가능 처리를 해야함.
잔액확인 (checkBalance)
1) 이름, 계좌번호를 입력받고 해당 고객의 잔액을 출력함.
참고
//
Scanner sc = new Scanner(System.in);
List<BankDTO> bList = new ArrayList<>();
BankDTO b = new BankDTO();
BankService bs = new BankService();
boolean run = true;
int choice = 0;
while (run) {
System.out.println("-------------------------------------------------");
System.out.println("1.고객등록 | 2.고객조회 | 3.입금 | 4.출금 | 5.잔액 | 6.종료");
System.out.println("-------------------------------------------------");
System.out.print("번호 > ");
choice = sc.nextInt();
switch (choice) {
case 1: { // 고객등록
bList = bs.clientJoin(bList);
break;
}
case 2: { // 전체조회
bs.clientListView(bList);
break;
}
case 3: { // 입금
bList = bs.deposit(bList);
break;
}
case 4: { // 출금
bList = bs.withdraw(bList);
break;
}
case 5: { // 잔액
bs.checkBalance(bList);
break;
}
case 6: { // 종료
System.out.println("종료합니다.");
run = false;
break;
}
default: {
System.out.println("다시 입력하세요");
break;
}
}
}
// 고객등록 전체고객조회 입금 출금 잔액확인
Scanner sc = new Scanner(System.in);
// 고객등록
// 메서드 이름 : clientJoin
// 리턴 타입 : List<BankDTO>
// 매개변수 : List<BankDTO>
//
//
List<BankDTO> clientJoin(List<BankDTO> bList) {
System.out.print("이름 : ");
String name = sc.nextLine();
System.out.print("계좌번호 : ");
String accountNumber = sc.nextLine();
int clientNumber = bList.size() + 1;
BankDTO b = new BankDTO(clientNumber, name, accountNumber);
bList.add(b);
return bList;
}
// 전체 고객 조회
// 메서드 이름 : clientListView
// 리턴 타입 :void
// 매개변수 : List<BankDTO>
//
//
void clientListView(List<BankDTO> bList) {
for (BankDTO b : bList) {
System.out.println(b);
}
}
// 입금
// 메서드 이름 : deposit
// 리턴 타입 : List<BankDTO>
// 매개변수 : List<BankDTO>
//
//
List<BankDTO> deposit(List<BankDTO> bList) {
System.out.print("이름 : ");
String name = sc.nextLine();
System.out.print("계좌번호 : ");
String accountNumber = sc.nextLine();
int checkNumber = -1;
for (int i = 0; i < bList.size(); i++) {
if (bList.get(i).getName().equals(name) && bList.get(i).getAccountNumber().equals(accountNumber)) {
checkNumber = i;
}
}
if (checkNumber >= 0) {
System.out.print("입금 금액 : ");
int money = sc.nextInt();
bList.get(checkNumber).setBalance(money);
} else {
System.out.println("정보가 틀립니다.");
}
// int check = nameAccountNumberCheck(bList);
// if (check >= 0) {
// System.out.print("입금 금액 : ");
// int money = sc.nextInt();
// bList.get(check).setBalance(money);
// } else {
// System.out.println("정보가 틀립니다.");
// }
return bList;
}
// 출금
// 메서드 이름 :withdraw
// 리턴 타입 : List<BankDTO>
// 매개변수 : List<BankDTO>
//
//
List<BankDTO> withdraw(List<BankDTO> bList) {
System.out.print("이름 : ");
sc.nextLine(); // 망할 스캐너 때문에 넣음
String name = sc.nextLine();
System.out.print("계좌번호 : ");
String accountNumber = sc.nextLine();
int checkNumber = -1;
for (int i = 0; i < bList.size(); i++) {
if (bList.get(i).getName().equals(name) && bList.get(i).getAccountNumber().equals(accountNumber)) {
checkNumber = i;
}
}
if (checkNumber >= 0) {
System.out.print("출금 금액 : ");
int money = sc.nextInt();
if (bList.get(checkNumber).getBalance()>money) {
bList.get(checkNumber).setBalance(bList.get(checkNumber).getBalance()-money);
} else {
System.out.println("잔액이 부족합니다");
}
} else {
System.out.println("정보가 틀립니다.");
}
// int check = nameAccountNumberCheck(bList);
// if (check >= 0) {
// System.out.print("출금 금액 : ");
// int money = sc.nextInt();
// bList.get(check).setBalance(-money);
// } else {
// System.out.println("정보가 틀립니다.");
// }
return bList;
}
// 잔액 확인
// 메서드 이름 : checkBalance
// 리턴 타입 : void
// 매개변수 : List<BankDTO>
//
//
void checkBalance(List<BankDTO> bList) {
System.out.print("이름 : ");
sc.nextLine(); // 망할 스캐너 때문에 넣음
String name = sc.nextLine();
System.out.print("계좌번호 : ");
String accountNumber = sc.nextLine();
int checkNumber = -1;
for (int i = 0; i < bList.size(); i++) {
if (bList.get(i).getName().equals(name) && bList.get(i).getAccountNumber().equals(accountNumber)) {
checkNumber = i;
}
}
if (checkNumber >= 0) {
System.out.println("잔액 : "+bList.get(checkNumber).getBalance());
} else {
System.out.println("정보가 틀립니다.");
}
// int check = nameAccountNumberCheck(bList);
// if (check >= 0) {
// System.out.println(bList.get(check).getBalance());
// } else {
// System.out.println("정보가 틀립니다.");
// }
}
// 이름 계좌번호check
// 메서드 이름 : checkBalance
// 리턴 타입 : int
// 매개변수 : List<BankDTO>
// 스캐너 때문에 이거 못씀 ㅠㅠ
// int nameAccountNumberCheck(List<BankDTO> bList) {
// System.out.print("이름 : ");
// String name = sc.nextLine();
// System.out.print("계좌번호 : ");
// String accountNumber = sc.nextLine();
// int checkNumber = -1;
// for (int i = 0; i < bList.size(); i++) {
// if (bList.get(i).getName().equals(name) && bList.get(i).getAccountNumber().equals(accountNumber)) {
// checkNumber = i;
// }
// }
//
// return checkNumber;
// }
private int clientNumber =0;
private String name ="";
private String accountNumber ="";
private int balance =0;
BankDTO(){ //기본생성자
}
public BankDTO(int clientNumber, String name, String accountNumber, int balance) {
super();
this.clientNumber = clientNumber;
this.name = name;
this.accountNumber = accountNumber;
this.balance = balance;
}
public BankDTO(int clientNumber, String name, String accountNumber) {
super();
this.clientNumber = clientNumber;
this.name = name;
this.accountNumber = accountNumber;
this.balance = balance;
}
public int getClientNumber() {
return clientNumber;
}
public void setClientNumber(int clientNumber) {
this.clientNumber = clientNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}
public int getBalance() {
return balance;
}
public void setBalance(int balance) {
this.balance = balance;
}
@Override
public String toString() {
return "BankDTO [clientNumber=" + clientNumber + ", name=" + name + ", accountNumber=" + accountNumber
+ ", balance=" + balance + "]";
}
두개의 메서드안에서 중복되는 부분을 따로 메서드로 만들어서 따로 사용이 가능
loginCheck 메서드를 따로 만들어서 로그인메서드와 이메일변경 메서드에 넣을 수는 있지만 어떤 사람의 로그인인지 확인을 할 수 없다
로그인 체크 메서드는 boolean값으로 리턴을 보내기 때문에 누가 성공을 한지 모른다
로그인체크 메서드를 boolean값 말고 int값으로 보내서 값이 0이하면 로그인 실패
0이상이면 로그인 성공
그리고 int값을 인덱스 값을 사용해서
하루에 한번이라니 너무하잔아...
심심해...
다음주 중간까지만 자바를 하고 한달 뒤에 다시 자바로 돌아온다?
오오 다음꺼 배우는구나 좋아좋아 ㅎㅎㅎ