Advertisement
Guest User

Untitled

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