Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.14 KB | None | 0 0
  1. import java.util.LinkedList;
  2. import java.util.Scanner;
  3.  
  4. public class ATM {
  5. static LinkedList<Customer> customerList = new LinkedList<Customer>();
  6. static Scanner sc = new Scanner(System.in);
  7.  
  8. public static void main(String Args[]) {
  9. boolean cont = true;
  10.  
  11. //Loop for login and creation
  12.  
  13. while(cont){
  14. System.out.println(" ");
  15. System.out.println("Type Login to login or Create to create a new account");
  16. System.out.println(" ");
  17. String answer = sc.nextLine();
  18. if(answer.equalsIgnoreCase("create")) {
  19. customerCreation();
  20. } else if(answer.equalsIgnoreCase("login")){
  21. accountManipulation(login());
  22. }
  23. }
  24. sc.close();
  25.  
  26. }
  27.  
  28. public static Customer login() {
  29.  
  30. System.out.println("Enter your name");
  31. String name = sc.nextLine();
  32.  
  33. System.out.println("Enter your PIN");
  34. int PIN = sc.nextInt();
  35.  
  36. for(int i = 0; i < customerList.size(); i++) {
  37. if(customerList.get(i).getName().equalsIgnoreCase(name) && customerList.get(i).getpIN() == PIN){
  38. System.out.println("Login Successful");
  39. return customerList.get(i);
  40. }
  41. }
  42. System.out.println("Login not found, try again");
  43. System.out.println();
  44. return null;
  45. }
  46.  
  47. public static void customerCreation() {
  48. System.out.println("What is your name?");
  49. String nameX = sc.nextLine();
  50. int PIN = 0;
  51.  
  52. boolean pin = true;
  53. while(pin) {
  54. System.out.println("Enter a 4 digit number to use as a pin:");
  55. PIN = sc.nextInt();
  56. if(PIN > 999 && PIN < 10000) {
  57. pin = false;
  58. } else {
  59. System.out.println("Entered PIN is not valid");
  60. }
  61. }
  62. Customer y = new Customer(nameX, PIN);
  63. customerList.add(y);
  64. accountCreation(y);
  65.  
  66. }
  67.  
  68. public static void accountCreation(Customer x) {
  69. boolean cont1 = true,cont2 = true,cont3 = true;
  70. int overdraft1 = 0, overdraft2 = 0, overdraft3 = 0;
  71.  
  72. System.out.println("Enter starting amount for Checking account: ");
  73. int deposit1 = sc.nextInt();
  74. while(cont1) {
  75. System.out.println("Enter Overdraft Preference: ");
  76. System.out.println("1 - Deny withdraw if it is greater than balance");
  77. System.out.println("2 - Allow withdraw if it is greater than balance and fine 25$ to my account");
  78. overdraft1 = sc.nextInt();
  79. if(overdraft1 < 1 || overdraft1 > 2) {
  80. System.out.println("Invalid choice, try again");
  81. } else {
  82. cont1 = false;
  83. }
  84. }
  85. x.addAccount(new Checking(overdraft1));
  86. x.findAccount("Checking").deposit(deposit1);
  87.  
  88. System.out.println("Enter starting amount for Savings account: ");
  89. int deposit2 = sc.nextInt();
  90.  
  91. while(cont2) {
  92. System.out.println("Enter Overdraft Preference: ");
  93. System.out.println("1 - Deny withdraw if it is greater than balance");
  94. System.out.println("2 - Allow withdraw if it is greater than balance and fine 25$ to my account");
  95. overdraft2 = sc.nextInt();
  96. if(overdraft2 < 1 || overdraft2 > 2) {
  97. System.out.println("Invalid choice, try again");
  98. } else {
  99. cont2 = false;
  100. }
  101. }
  102. x.addAccount(new Savings(overdraft2));
  103. x.findAccount("Savings").deposit(deposit2);
  104.  
  105. System.out.println("Enter starting amount for Business account: ");
  106. int deposit3 = sc.nextInt();
  107.  
  108. while(cont3) {
  109. System.out.println("Enter Overdraft Preference: ");
  110. System.out.println("1 - Deny withdraw if it is greater than balance");
  111. System.out.println("2 - Allow withdraw if it is greater than balance and fine 25$ to my account");
  112. overdraft3 = sc.nextInt();
  113. if(overdraft3 < 1 || overdraft3 > 2) {
  114. System.out.println("Invalid choice, try again");
  115. } else {
  116. cont3 = false;
  117. }
  118. }
  119. x.addAccount(new Business(overdraft3));
  120. x.findAccount("Business").deposit(deposit3);
  121. }
  122.  
  123. public static void accountManipulation(Customer x) {
  124. boolean cont = true;
  125. if(x == null) {
  126. cont = false;
  127. }
  128.  
  129. while(cont) {
  130. System.out.println("Hello " + x.getName());
  131. System.out.println("Enter the number of the option you want.");
  132. System.out.println("1 - View all accounts");
  133. System.out.println("2 - Make a deposit");
  134. System.out.println("3 - Make a transfer");
  135. System.out.println("4 - Make a withdraw");
  136. System.out.println("5 - Change PIN");
  137. System.out.println("6 - View UID");
  138. System.out.println("7 - Logout");
  139. int choice = sc.nextInt();
  140.  
  141. switch(choice) {
  142. case 1:
  143. x.showAccounts();
  144. break;
  145. case 2:
  146. System.out.println("How much do you want to deposit?");
  147. int deposit = sc.nextInt();
  148.  
  149. System.out.println("What account do you want to deposit to?");
  150. System.out.println("1 - Savings");
  151. System.out.println("2 - Checking");
  152. System.out.println("3 - Business");
  153. int choice2 = sc.nextInt();
  154. switch(choice2) {
  155. case 1:
  156. if(x.findAccount("Savings") == null) {
  157. System.out.println("Account not found, try again");
  158. break;
  159. }
  160. x.findAccount("Savings").deposit(deposit);
  161. break;
  162. case 2:
  163. if(x.findAccount("Checking") == null) {
  164. System.out.println("Account not found, try again");
  165. break;
  166. }
  167. x.findAccount("Checking").deposit(deposit);
  168. break;
  169. case 3:
  170. if(x.findAccount("Business") == null) {
  171. System.out.println("Account not found, try again");
  172. break;
  173. }
  174. x.findAccount("Business").deposit(deposit);
  175. break;
  176. }
  177. break;
  178. case 3:
  179. System.out.println("How much do you want to transfer?");
  180. double transfer = sc.nextDouble();
  181.  
  182. System.out.println("Enter the UID of the person you want to transfer to.");
  183. int uid = sc.nextInt();
  184. int person = 0;
  185.  
  186. for(int i = 0; i < customerList.size(); i++) {
  187. if(customerList.get(i).getuID() == uid) {
  188. person = i;
  189. }
  190. }
  191.  
  192. String from;
  193.  
  194. System.out.println("What account do you want to transfer from?");
  195. System.out.println("1 - Savings");
  196. System.out.println("2 - Checking");
  197. System.out.println("3 - Business");
  198.  
  199. int choice1 = sc.nextInt();
  200. if(choice1 == 1) {
  201. from = "Savings";
  202. } else if(choice == 2) {
  203. from = "Checking";
  204. } else if(choice == 3) {
  205. from = "Business";
  206. } else {
  207. from = "Checking";
  208. }
  209.  
  210.  
  211. System.out.println("What account do you want to transfer to?");
  212. System.out.println("1 - Savings");
  213. System.out.println("2 - Checking");
  214. System.out.println("3 - Business");
  215. int choice3 = sc.nextInt();
  216. switch(choice3) {
  217. case 1:
  218. if(!x.findAccount(from).transfer(transfer, customerList.get(person).findAccount("Savings"))) {
  219. System.out.println("Transfer Failed");
  220. }
  221. break;
  222. case 2:
  223. if(!x.findAccount(from).transfer(transfer, customerList.get(person).findAccount("Checking"))) {
  224. System.out.println("Transfer Failed");
  225. }
  226. break;
  227. case 3:
  228. if(!x.findAccount(from).transfer(transfer, customerList.get(person).findAccount("Business"))) {
  229. System.out.println("Transfer Failed");
  230. }
  231. break;
  232. }
  233. break;
  234.  
  235. case 4:
  236. System.out.println("How much do you want to withdraw?");
  237. int withdraw = sc.nextInt();
  238.  
  239. System.out.println("What account do you want to withdraw from?");
  240. System.out.println("1 - Savings");
  241. System.out.println("2 - Checking");
  242. System.out.println("3 - Business");
  243. int choice4 = sc.nextInt();
  244. switch(choice4) {
  245. case 1:
  246. x.findAccount("Savings").withdraw(withdraw);
  247. break;
  248. case 2:
  249. x.findAccount("Checking").withdraw(withdraw);
  250. break;
  251. case 3:
  252. x.findAccount("Business").withdraw(withdraw);
  253. break;
  254. }
  255. break;
  256.  
  257. case 5:
  258. int newPIN = 0;
  259. int oldPIN = 0;
  260. System.out.println("Enter your current PIN");
  261. oldPIN = sc.nextInt();
  262.  
  263. System.out.println("Enter new PIN");
  264. newPIN = sc.nextInt();
  265.  
  266. if(x.changePIN(newPIN, oldPIN) == false) {
  267. System.out.println("Incorrect PIN entered.");
  268. } else {
  269. System.out.println("Pin changed");
  270. }
  271. break;
  272. case 6:
  273. System.out.println("Your UID is: " + x.getuID());
  274. break;
  275. case 7:
  276. System.out.println("You have logged out.");
  277. cont = false;
  278. break;
  279. }
  280. }
  281. }
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement