Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 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(money +"만큼 인출 완료");
  31. balance -= money; //출금액만큼 잔고를 감소
  32. return money; //출금액 반환
  33. }
  34.  
  35. boolean Send(Account acc, int money, String password)
  36. {
  37. int sendmoney = Withraw(money, password);
  38. if (sendmoney > 0)
  39. {
  40. acc.Deposit(sendmoney);
  41. return true;
  42. }
  43. return false;
  44. }
  45.  
  46. boolean balanceCheck(String password)
  47. {
  48. if(this.password.equals(password) == false)
  49. {
  50. return false;
  51. }
  52. else
  53. {
  54. return true;
  55. }
  56. }
  57. }
  58.  
  59. public class atm_example {
  60. static int ManagerMonitor(Account acc[], int cnt)
  61. {
  62. Scanner in = new Scanner(System.in);
  63. String name = "", AccNo = "", password = "";
  64. int balance = 0;
  65. int accIndex = -1;
  66. while(true)
  67. {
  68. System.out.println("관리자 화면");
  69. System.out.print("1. 계좌생성 2.계좌삭제 3.계좌현황 4.돌아가기 : ");
  70. int select = in.nextInt();
  71. switch(select)
  72. {
  73. case 1: //계좌생성
  74. in.nextLine(); //출력버퍼사용
  75. System.out.println("예금주 : "); name = in.nextLine();
  76. System.out.println("계좌번호 : "); AccNo = in.nextLine();
  77. accIndex = findAccountIndex(acc, cnt, AccNo);
  78. if(accIndex == -1)
  79. {
  80. System.out.println("비밀번호 : "); password = in.nextLine();
  81. System.out.println("잔고 : "); balance = in.nextInt();
  82. acc[cnt++] = new Account(name, AccNo, balance, password);
  83. }
  84. else
  85. {
  86. System.out.println("이미 계설된 계좌입니다.");
  87. }
  88. break;
  89. case 2:
  90. System.out.println("삭제할 계좌번호를 적어주세요 : ");
  91. in.nextLine();
  92. AccNo = in.nextLine();
  93. for(int i = 0; i < accIndex; i++)
  94. if(acc[i].AccNo.equals(AccNo))
  95. {
  96. acc[i] = acc[i+1];
  97. System.out.println("삭제되었음");
  98. }
  99. else
  100. {
  101. System.out.println("없는 계좌입니다");
  102. }
  103. break;
  104. case 3:
  105. System.out.println("예금주\t계좌번호");
  106. System.out.println("=====================");
  107. for(int i=0; i<cnt; i++)
  108. {
  109. System.out.println(acc[i].name + "\t" + acc[i].AccNo);
  110. }
  111. break;
  112. case 4: return cnt;
  113. }
  114. }
  115. }
  116. static void ClientMonitor(Account acc[], int cnt, Account user) {
  117. Scanner in = new Scanner(System.in);
  118. String name = "", AccNo = "", password = "";
  119. int money = 0;
  120. int accIndex = -1;
  121. boolean successed = true;
  122. while(true)
  123. {
  124. System.out.println("고객화면");
  125. System.out.print("1.입금 2.출금 3.송금 4.조회 5.로그아웃 : ");
  126. int select = in.nextInt();
  127. switch(select)
  128. {
  129. case 1:
  130. System.out.print("입금금액 : ");
  131. money = in.nextInt();
  132. user.Deposit(money);
  133. System.out.println("입금완료");
  134. break;
  135. case 2:
  136. System.out.println("얼마를 인출하시겠습니까? : ");
  137. money = in.nextInt();
  138. in.nextLine();
  139. System.out.println("비밀번호를 입력하세요 : ");
  140. password = in.nextLine();
  141. user.Withraw(money, password);
  142. break;
  143. case 3:
  144. in.nextLine();
  145. System.out.println("누구에게 송금하시곘습니까?");
  146. AccNo = in.nextLine();
  147. accIndex = findAccountIndex(acc, cnt, AccNo);
  148. if(accIndex == -1)
  149. {
  150. System.out.println("계좌가 존재하지 않습니다");
  151. return;
  152. }
  153. else
  154. {
  155. System.out.println("얼마를 송금하시겠습니까?");
  156. money = in.nextInt();
  157. in.nextLine();
  158. System.out.println("비밀번호를 입력하세요");
  159. password = in.nextLine();
  160. }
  161. successed = user.Send(acc[accIndex], money, password);
  162. if(successed == true)
  163. {
  164. System.out.println("송금 성공");
  165. }
  166. else
  167. {
  168. System.out.println("송금 실패");
  169. return;
  170. }
  171. break;
  172. case 4:
  173. System.out.println("비밀번호를 입력하세요 : ");
  174. in.nextLine();
  175. password = in.nextLine();
  176. if(user.balanceCheck(password) == true)
  177. {
  178. System.out.println("예금주\t계좌번호\t예금액");
  179. System.out.println("==============================");
  180. System.out.println(user.name + "\t" + user.AccNo + "\t " + user.balance + "원");
  181. }
  182. else
  183. {
  184. System.out.println("비밀번호가 다릅니다.");
  185. }
  186. break;
  187. case 5: return;
  188. }
  189. }
  190. }
  191.  
  192. static int findAccountIndex(Account acc[], int cnt, String AccNo)
  193. {
  194. for(int i=0; i<cnt; i++)
  195. {
  196. if(acc[i].AccNo.equals(AccNo))
  197. {
  198. return i;
  199. }
  200. }
  201. return -1;
  202. }
  203.  
  204. public static void main(String[] args) {
  205. // TODO Auto-generated method stub
  206. Account acc[] = new Account[100];
  207. int cnt=0; //초기 계좌수
  208. Scanner in = new Scanner(System.in); //입력을 받을 scanner 객체
  209.  
  210. //acc[0] = new Account("장용훈", "1234-1234", 10000, "1234");
  211. while(true)//시작화면과 메뉴 받기
  212. {
  213. System.out.println("시작화면");
  214. System.out.print("1.관리자화면 2. 로그인 3. 종료 : ");
  215. int select = in.nextInt();
  216. switch(select)
  217. {
  218. case 1: cnt = ManagerMonitor(acc, cnt);
  219. break;
  220. case 2:
  221. // 계좌입력
  222. in.nextLine();// 출력 버퍼 해결
  223. System.out.print("계좌번호 : ");
  224. String AccNo = in.nextLine();
  225.  
  226. // 계좌가 있는지 확인.
  227. int index = findAccountIndex(acc, cnt, AccNo);
  228. if(index >= 0) // 계좌가 존재하면 고객화면 호출
  229. {
  230. ClientMonitor(acc, cnt, acc[index]);
  231. }
  232. //
  233. break;
  234. case 3: return; //종료
  235. }
  236. }
  237. }
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement