Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import javax.swing.*;
  3.  
  4. class Bank implements Comparable {
  5.  
  6. private double bal;
  7. private int accountNumber;
  8. private String accountName;
  9. public Bank() {
  10. }
  11.  
  12. void display_details() {
  13. System.out.println("Account Number : " + accountNumber);
  14. System.out.println("Account Balance : " + bal + "\n\n\n");
  15. JOptionPane.showMessageDialog(null, "\nAccount Number : " + accountNumber + "\nAccount Balance : " + bal);
  16. }
  17.  
  18. public void deposit(double depositAmount) {
  19. bal += depositAmount;
  20. }
  21.  
  22. public void withdraw(double withdrawAmount) {
  23. if (withdrawAmount > bal) {
  24. JOptionPane.showMessageDialog(null, "Insufficient Funds");
  25. } else {
  26. bal -= withdrawAmount;
  27. }
  28. }
  29. @Override
  30. public int compareTo(Object arg0) {
  31. // TODO Auto-generated method stub
  32. return 0;
  33. }
  34.  
  35. public double getBal() {
  36. return bal;
  37. }
  38.  
  39. public void setBal(double baL) {
  40. bal = baL;
  41. }
  42.  
  43. public int getAccountNumber() {
  44. return accountNumber;
  45. }
  46.  
  47. public void setAccountNumber(int accountNumbe) {
  48. accountNumber = accountNumbe;
  49. }
  50.  
  51. public String getAccountName() {
  52. return accountName;
  53. }
  54.  
  55. }
  56.  
  57. class FinancialFolk implements PasswordVerifivation {
  58. private String accountUsername, accountHolderName, accountPassword;
  59. protected static ArrayList<Bank> accounts = new ArrayList<>();
  60. protected static ArrayList<FinancialFolk> Bank = new ArrayList<>();
  61.  
  62. public FinancialFolk(String username, String name, String password) {
  63. accountUsername = username;
  64. accountHolderName = name;
  65. accountPassword = password;
  66. }
  67.  
  68. public FinancialFolk() {
  69. accountUsername = "";
  70. accountHolderName = "";
  71. accountPassword = "";
  72. }
  73.  
  74. public void passwordCreation() {
  75. accountPassword = JOptionPane.showInputDialog("Please choose a secure password for your account.");
  76. }
  77.  
  78. public boolean passwordVerify(String attemptedPassword) {
  79. return accountPassword.equals(attemptedPassword);
  80.  
  81. }
  82.  
  83. public boolean createNewPerson() { // Creates a new FinancialFolk.
  84. accountHolderName = (JOptionPane.showInputDialog("Please enter your name."));
  85. accountUsername = (JOptionPane.showInputDialog("Please enter a username for your account."));
  86. passwordCreation();
  87. }
  88.  
  89. public static void createNewAccount() { // Adds an account to an existing FinancialFolk.
  90. String[] buttons = { "Checking", "Savings" };
  91. int acc = JOptionPane.showOptionDialog(null, "What type of account would you like to make?", "Bank",
  92. JOptionPane.PLAIN_MESSAGE, 3, null, buttons, buttons[1]);
  93. switch (acc) {
  94. case 0:
  95. accounts.add(null);
  96.  
  97. case 1:
  98. accounts.add(null);
  99. }
  100.  
  101. }
  102.  
  103. public static void main(String[] args) {
  104. Bank user = new Bank();
  105. FinancialFolk FF = new FinancialFolk();
  106. boolean exit = false;
  107. do {
  108. String[] buttons = { "Create Account For The First Time", "Login", "Exit Bank" };
  109. int rc = JOptionPane.showOptionDialog(null, "What would you like to do?", "Bank", JOptionPane.PLAIN_MESSAGE,
  110. 3, null, buttons, buttons[2]);
  111. switch (rc) {
  112. case 0: // create account
  113. FF.createNewPerson();
  114. Bank.add(FF);
  115. createNewAccount();
  116. break;
  117. case 1: // login
  118. boolean logout = false;
  119. boolean incun = true;
  120. String an = JOptionPane.showInputDialog("Enter your username.\n");
  121. for (FinancialFolk x : Bank) {
  122. if (x.getAccountUsername().equals(an)) {
  123. incun=false;
  124. if (x.passwordVerify(JOptionPane.showInputDialog("Enter your acccount password.\n"))) {
  125. do {
  126. String[] buttons2 = { "View all accounts.", "Deposit into an account",
  127. "Withdraw from your account", "Logout" };
  128. int rc2 = JOptionPane.showOptionDialog(null, "What would you like to do?", "Bank",
  129. JOptionPane.PLAIN_MESSAGE, 3, null, buttons2, buttons2[3]);
  130. switch (rc2) {
  131. case 0: // all accounts
  132. int networth = 0;
  133. for (Bank acct : accounts) {
  134. acct.display_details();
  135. networth += acct.getBal();
  136. }
  137. JOptionPane.showMessageDialog(null, "Your account total is: $" + networth);
  138. case 1: // deposit
  139. if (accounts.size() == 0)
  140. JOptionPane.showMessageDialog(null, "You do not have any accounts!");
  141. else if (accounts.size() == 1) {
  142. accounts.get(0).deposit(Integer.parseInt(JOptionPane
  143. .showInputDialog("Enter how many dollars you want to deposit.\n")));
  144. } else {
  145. String a = (JOptionPane
  146. .showInputDialog("Enter the account name to deposit into.\n"));
  147. for (Bank act : accounts) {
  148. if (act.getAccountName().equalsIgnoreCase(a))
  149. act.deposit(Integer.parseInt(JOptionPane.showInputDialog(
  150. "Enter how many dollars you want to deposit.\n")));
  151. }
  152. }
  153. case 2:
  154. if (accounts.size() == 0)
  155. JOptionPane.showMessageDialog(null, "You do not have any accounts!");
  156. else if (accounts.size() == 1) {
  157. accounts.get(0).withdraw(Integer.parseInt(JOptionPane
  158. .showInputDialog("Enter how many dollars you want to withdraw.\n")));
  159. } else {
  160. String a = (JOptionPane
  161. .showInputDialog("Enter the account name to withdraw from.\n"));
  162. for (Bank act : accounts) {
  163. if (act.getAccountName().equalsIgnoreCase(a))
  164. act.deposit(Integer.parseInt(JOptionPane.showInputDialog(
  165. "Enter how many dollars you want to withdraw.\n")));
  166. }
  167. }
  168. case 3:
  169. logout = true;
  170. }
  171. } while (!logout);
  172. } else
  173. JOptionPane.showMessageDialog(null, "Incorrect password");
  174. }
  175. }
  176. if (incun)
  177. JOptionPane.showMessageDialog(null, "Invalid Username");
  178. break;
  179. case 2:
  180. JOptionPane.showMessageDialog(null, "Thank you for using the JacoBank");
  181. exit = true;
  182. break;
  183.  
  184. }
  185. } while (!exit);
  186. }
  187.  
  188. public String getAccountHolderName() {
  189. return accountHolderName;
  190. }
  191.  
  192. public void setAccountHolderName(String accountHolderName) {
  193. this.accountHolderName = accountHolderName;
  194. }
  195.  
  196. public String getAccountUsername() {
  197. return accountUsername;
  198. }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement