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(money +"만큼 인출 완료");
- 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;
- }
- boolean balanceCheck(String password)
- {
- if(this.password.equals(password) == false)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- }
- public class atm_example {
- static int ManagerMonitor(Account acc[], int cnt)
- {
- Scanner in = new Scanner(System.in);
- String name = "", AccNo = "", password = "";
- int balance = 0;
- int accIndex = -1;
- int delete = -1;
- 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();
- accIndex = findAccountIndex(acc, cnt, AccNo);
- if(accIndex == -1)
- {
- System.out.println("비밀번호 : "); password = in.nextLine();
- System.out.println("잔고 : "); balance = in.nextInt();
- acc[cnt++] = new Account(name, AccNo, balance, password);
- }
- else
- {
- System.out.println("이미 계설된 계좌입니다.");
- }
- break;
- case 2:
- in.nextLine();
- System.out.println("삭제할 계좌번호를 적어주세요 : ");
- AccNo = in.nextLine();
- int index = 0;
- delete = deleteAccount(acc, cnt, index);
- if( delete == index )
- {
- System.out.println("존재하지 않는 계좌입니다.");
- }
- else
- {
- System.out.println("삭제 되었습니다.");
- }
- 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);
- return cnt;
- }
- 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;
- int accIndex = -1;
- boolean successed = true;
- 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:
- in.nextLine();
- System.out.println("누구에게 송금하시곘습니까?");
- AccNo = in.nextLine();
- accIndex = findAccountIndex(acc, cnt, AccNo);
- if(accIndex == -1)
- {
- System.out.println("계좌가 존재하지 않습니다");
- return;
- }
- else
- {
- System.out.println("얼마를 송금하시겠습니까?");
- money = in.nextInt();
- in.nextLine();
- System.out.println("비밀번호를 입력하세요");
- password = in.nextLine();
- }
- successed = user.Send(acc[accIndex], money, password);
- if(successed == true)
- {
- System.out.println("송금 성공");
- }
- else
- {
- System.out.println("송금 실패");
- return;
- }
- break;
- case 4:
- System.out.println("비밀번호를 입력하세요 : ");
- in.nextLine();
- password = in.nextLine();
- if(user.balanceCheck(password) == true)
- {
- System.out.println("예금주\t계좌번호\t예금액");
- System.out.println("==============================");
- System.out.println(user.name + "\t" + user.AccNo + "\t " + user.balance + "원");
- }
- else
- {
- System.out.println("비밀번호가 다릅니다.");
- }
- break;
- case 5: return;
- }
- }
- }
- static int deleteAccount (Account acc[], int cnt, int index)
- {
- if(cnt == 0)
- {
- return 0;
- }
- if(cnt <= index)
- {
- return cnt;
- }
- for(int i = index; i <cnt; i++)
- {
- acc[i] = acc[i+1];
- }
- return cnt +1;
- }
- 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);
- 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]);
- }
- else
- {
- System.out.println("계좌가 없습니다.");
- }
- break;
- case 3:
- System.out.println("시스템을 종료합니다.");
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement