Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Account
- {
- String name; //예금주
- String AccNo; //계좌번호
- int balance; //잔고
- String password; //비밀번호
- Account(String name, String AccNo, int balance, String password)
- { // 계좌를 초기화.
- this.name = name; this.AccNo = AccNo; this.balance = balance;
- this.password = password;
- }
- void Deposit(int money)
- {
- balance += money; //입금액만큼 잔고를 증가
- }
- int Withraw(int money, String password)
- {
- if(this.password.equals(password) == false)// 비밀번호확인
- {
- System.out.println("비밀번호틀림");
- return 0;
- }
- if(balance < money)// 잔고확인
- {
- System.out.println("잔고부족");
- return 0;
- }
- System.out.println("인출 완료");
- balance -= money; //출금액만큼 잔고를 감소
- return money; //출금액 반환
- }
- boolean Send(Account acc, int money, String password)
- {
- int sendmoney = Withraw(money, password);
- if (sendmoney > 0)
- {
- acc.Deposit(sendmoney);
- return true;
- }
- return false;
- }
- int balanceCheck(int AccNo, String password)
- {
- if(this.password.equals(password) == false)
- {
- System.out.println("wrong");
- return 0;
- }
- if(this.AccNo.equals(AccNo))
- {
- System.out.println("맞음");
- }
- }
- }
- public class atm_example {
- static int ManagerMonitor(Account acc[], int cnt)
- {
- Scanner in = new Scanner(System.in);
- String name = "", AccNo = "", password = "";
- int balance = 0;
- while(true)
- {
- System.out.println("관리자 화면");
- System.out.print("1. 계좌생성 2.계좌삭제 3.계좌현황 4.돌아가기 : ");
- int select = in.nextInt();
- switch(select)
- {
- case 1: //계좌생성
- in.nextLine(); //출력버퍼사용
- System.out.println("예금주 : "); name = in.nextLine();
- System.out.println("계좌번호 : "); AccNo = in.nextLine();
- System.out.println("비밀번호 : "); password = in.nextLine();
- System.out.println("잔고 : "); balance = in.nextInt();
- acc[cnt++] = new Account(name, AccNo, balance, password);
- break;
- case 2: break;
- case 3:
- System.out.println("예금주\t계좌번호");
- System.out.println("=====================");
- for(int i=0; i<cnt; i++)
- {
- System.out.println(acc[i].name + "\t" + acc[i].AccNo);
- }
- break;
- case 4: return cnt;
- }
- }
- }
- static void ClientMonitor(Account acc[], int cnt, Account user) {
- Scanner in = new Scanner(System.in);
- String name = "", AccNo = "", password = "";
- int money = 0;
- while(true)
- {
- System.out.println("고객화면");
- System.out.print("1.입금 2.출금 3.송금 4.조회 5.로그아웃 : ");
- int select = in.nextInt();
- switch(select)
- {
- case 1:
- System.out.print("입금금액 : ");
- money = in.nextInt();
- user.Deposit(money);
- System.out.println("입금완료");
- break;
- case 2:
- System.out.println("얼마를 인출하시겠습니까? : ");
- money = in.nextInt();
- in.nextLine();
- System.out.println("비밀번호를 입력하세요 : ");
- password = in.nextLine();
- user.Withraw(money, password);
- break;
- case 3:
- break;
- case 4:
- System.out.println("비밀번호를 입력하세요 : ");
- password = in.nextLine();
- in.nextLine();
- user.balanceCheck(password);
- System.out.println("예금자\t계좌번호\t예금액");
- System.out.println("=======================================");
- System.out.println(user.name + "\t" + user.AccNo +"\t"+ user.balance);
- break;
- case 5: return;
- }
- }
- }
- static int findAccountIndex(Account acc[], int cnt, String AccNo)
- {
- for(int i=0; i<cnt; i++)
- {
- if(acc[i].AccNo.equals(AccNo))
- {
- return i;
- }
- }
- return -1;
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Account acc[] = new Account[100];
- int cnt=0; //초기 계좌수
- Scanner in = new Scanner(System.in); //입력을 받을 scanner 객체
- //acc[0] = new Account("장용훈", "1234-1234", 10000, "1234");
- while(true)//시작화면과 메뉴 받기
- {
- System.out.println("시작화면");
- System.out.print("1.관리자화면 2. 로그인 3. 종료 : ");
- int select = in.nextInt();
- switch(select)
- {
- case 1: cnt = ManagerMonitor(acc, cnt);
- break;
- case 2:
- // 계좌입력
- in.nextLine();// 출력 버퍼 해결
- System.out.print("계좌번호 : ");
- String AccNo = in.nextLine();
- // 계좌가 있는지 확인.
- int index = findAccountIndex(acc, cnt, AccNo);
- if(index >= 0) // 계좌가 존재하면 고객화면 호출
- {
- ClientMonitor(acc, cnt, acc[index]);
- }
- //
- break;
- case 3: return; //종료
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement