Advertisement
Guest User

Untitled

a guest
Oct 12th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Account
  4. {
  5. String name; //예금주
  6. String AccNo; //계좌번호
  7. int balance; //잔고
  8. String password; //비밀번호
  9. Account(String name, String AccNo, int balance, String password)
  10. { // 계좌를 초기화.
  11. this.name = name; this.AccNo = AccNo; this.balance = balance;
  12. this.password = password;
  13. }
  14. void Deposit(int money)
  15. {
  16. balance += money; //입금액만큼 잔고를 증가
  17. }
  18. int Withraw(int money, String password)
  19. {
  20. if(this.password.equals(password) == false)// 비밀번호확인
  21. {
  22. System.out.println("비밀번호틀림");
  23. return 0;
  24. }
  25. if(balance < money)// 잔고확인
  26. {
  27. System.out.println("잔고부족");
  28. return 0;
  29. }
  30. System.out.println("인출 완료");
  31. balance -= money; //출금액만큼 잔고를 감소
  32. return money; //출금액 반환
  33. }
  34. boolean Send(Account acc, int money, String password)
  35. {
  36. int sendmoney = Withraw(money, password);
  37. if (sendmoney > 0)
  38. {
  39. acc.Deposit(sendmoney);
  40. return true;
  41. }
  42. return false;
  43. }
  44. int balanceCheck(int AccNo, String password)
  45. {
  46. if(this.password.equals(password) == false)
  47. {
  48. System.out.println("wrong");
  49. return 0;
  50. }
  51. if(this.AccNo.equals(AccNo))
  52. {
  53. System.out.println("맞음");
  54. }
  55. }
  56. }
  57.  
  58. public class atm_example {
  59. static int ManagerMonitor(Account acc[], int cnt)
  60. {
  61. Scanner in = new Scanner(System.in);
  62. String name = "", AccNo = "", password = "";
  63. int balance = 0;
  64. while(true)
  65. {
  66. System.out.println("관리자 화면");
  67. System.out.print("1. 계좌생성 2.계좌삭제 3.계좌현황 4.돌아가기 : ");
  68. int select = in.nextInt();
  69. switch(select)
  70. {
  71. case 1: //계좌생성
  72. in.nextLine(); //출력버퍼사용
  73. System.out.println("예금주 : "); name = in.nextLine();
  74. System.out.println("계좌번호 : "); AccNo = in.nextLine();
  75. System.out.println("비밀번호 : "); password = in.nextLine();
  76. System.out.println("잔고 : "); balance = in.nextInt();
  77. acc[cnt++] = new Account(name, AccNo, balance, password);
  78. break;
  79. case 2: break;
  80. case 3:
  81. System.out.println("예금주\t계좌번호");
  82. System.out.println("=====================");
  83. for(int i=0; i<cnt; i++)
  84. {
  85. System.out.println(acc[i].name + "\t" + acc[i].AccNo);
  86. }
  87.  
  88.  
  89. break;
  90. case 4: return cnt;
  91. }
  92. }
  93. }
  94. static void ClientMonitor(Account acc[], int cnt, Account user) {
  95. Scanner in = new Scanner(System.in);
  96. String name = "", AccNo = "", password = "";
  97. int money = 0;
  98. while(true)
  99. {
  100. System.out.println("고객화면");
  101. System.out.print("1.입금 2.출금 3.송금 4.조회 5.로그아웃 : ");
  102. int select = in.nextInt();
  103. switch(select)
  104. {
  105. case 1:
  106. System.out.print("입금금액 : ");
  107. money = in.nextInt();
  108. user.Deposit(money);
  109. System.out.println("입금완료");
  110. break;
  111. case 2:
  112. System.out.println("얼마를 인출하시겠습니까? : ");
  113. money = in.nextInt();
  114. in.nextLine();
  115. System.out.println("비밀번호를 입력하세요 : ");
  116. password = in.nextLine();
  117. user.Withraw(money, password);
  118. break;
  119. case 3:
  120.  
  121. break;
  122. case 4:
  123. System.out.println("비밀번호를 입력하세요 : ");
  124. password = in.nextLine();
  125. in.nextLine();
  126. user.balanceCheck(password);
  127. System.out.println("예금자\t계좌번호\t예금액");
  128. System.out.println("=======================================");
  129. System.out.println(user.name + "\t" + user.AccNo +"\t"+ user.balance);
  130. break;
  131. case 5: return;
  132. }
  133. }
  134. }
  135.  
  136. static int findAccountIndex(Account acc[], int cnt, String AccNo)
  137. {
  138. for(int i=0; i<cnt; i++)
  139. {
  140. if(acc[i].AccNo.equals(AccNo))
  141. {
  142. return i;
  143. }
  144. }
  145. return -1;
  146. }
  147.  
  148. public static void main(String[] args) {
  149. // TODO Auto-generated method stub
  150. Account acc[] = new Account[100];
  151. int cnt=0; //초기 계좌수
  152. Scanner in = new Scanner(System.in); //입력을 받을 scanner 객체
  153.  
  154. //acc[0] = new Account("장용훈", "1234-1234", 10000, "1234");
  155. while(true)//시작화면과 메뉴 받기
  156. {
  157. System.out.println("시작화면");
  158. System.out.print("1.관리자화면 2. 로그인 3. 종료 : ");
  159. int select = in.nextInt();
  160. switch(select)
  161. {
  162. case 1: cnt = ManagerMonitor(acc, cnt);
  163. break;
  164. case 2:
  165. // 계좌입력
  166. in.nextLine();// 출력 버퍼 해결
  167. System.out.print("계좌번호 : ");
  168. String AccNo = in.nextLine();
  169.  
  170. // 계좌가 있는지 확인.
  171. int index = findAccountIndex(acc, cnt, AccNo);
  172. if(index >= 0) // 계좌가 존재하면 고객화면 호출
  173. {
  174. ClientMonitor(acc, cnt, acc[index]);
  175. }
  176. //
  177. break;
  178. case 3: return; //종료
  179. }
  180. }
  181.  
  182.  
  183. }
  184.  
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement