Advertisement
Guest User

Untitled

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