Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import javax.swing.*;
- class Bank implements Comparable {
- private double bal;
- private int accountNumber;
- private String accountName;
- public Bank() {
- }
- void display_details() {
- System.out.println("Account Number : " + accountNumber);
- System.out.println("Account Balance : " + bal + "\n\n\n");
- JOptionPane.showMessageDialog(null, "\nAccount Number : " + accountNumber + "\nAccount Balance : " + bal);
- }
- public void deposit(double depositAmount) {
- bal += depositAmount;
- }
- public void withdraw(double withdrawAmount) {
- if (withdrawAmount > bal) {
- JOptionPane.showMessageDialog(null, "Insufficient Funds");
- } else {
- bal -= withdrawAmount;
- }
- }
- @Override
- public int compareTo(Object arg0) {
- // TODO Auto-generated method stub
- return 0;
- }
- public double getBal() {
- return bal;
- }
- public void setBal(double baL) {
- bal = baL;
- }
- public int getAccountNumber() {
- return accountNumber;
- }
- public void setAccountNumber(int accountNumbe) {
- accountNumber = accountNumbe;
- }
- public String getAccountName() {
- return accountName;
- }
- }
- class FinancialFolk implements PasswordVerifivation {
- private String accountUsername, accountHolderName, accountPassword;
- protected static ArrayList<Bank> accounts = new ArrayList<>();
- protected static ArrayList<FinancialFolk> Bank = new ArrayList<>();
- public FinancialFolk(String username, String name, String password) {
- accountUsername = username;
- accountHolderName = name;
- accountPassword = password;
- }
- public FinancialFolk() {
- accountUsername = "";
- accountHolderName = "";
- accountPassword = "";
- }
- public void passwordCreation() {
- accountPassword = JOptionPane.showInputDialog("Please choose a secure password for your account.");
- }
- public boolean passwordVerify(String attemptedPassword) {
- return accountPassword.equals(attemptedPassword);
- }
- public boolean createNewPerson() { // Creates a new FinancialFolk.
- accountHolderName = (JOptionPane.showInputDialog("Please enter your name."));
- accountUsername = (JOptionPane.showInputDialog("Please enter a username for your account."));
- passwordCreation();
- }
- public static void createNewAccount() { // Adds an account to an existing FinancialFolk.
- String[] buttons = { "Checking", "Savings" };
- int acc = JOptionPane.showOptionDialog(null, "What type of account would you like to make?", "Bank",
- JOptionPane.PLAIN_MESSAGE, 3, null, buttons, buttons[1]);
- switch (acc) {
- case 0:
- accounts.add(null);
- case 1:
- accounts.add(null);
- }
- }
- public static void main(String[] args) {
- Bank user = new Bank();
- FinancialFolk FF = new FinancialFolk();
- boolean exit = false;
- do {
- String[] buttons = { "Create Account For The First Time", "Login", "Exit Bank" };
- int rc = JOptionPane.showOptionDialog(null, "What would you like to do?", "Bank", JOptionPane.PLAIN_MESSAGE,
- 3, null, buttons, buttons[2]);
- switch (rc) {
- case 0: // create account
- FF.createNewPerson();
- Bank.add(FF);
- createNewAccount();
- break;
- case 1: // login
- boolean logout = false;
- boolean incun = true;
- String an = JOptionPane.showInputDialog("Enter your username.\n");
- for (FinancialFolk x : Bank) {
- if (x.getAccountUsername().equals(an)) {
- incun=false;
- if (x.passwordVerify(JOptionPane.showInputDialog("Enter your acccount password.\n"))) {
- do {
- String[] buttons2 = { "View all accounts.", "Deposit into an account",
- "Withdraw from your account", "Logout" };
- int rc2 = JOptionPane.showOptionDialog(null, "What would you like to do?", "Bank",
- JOptionPane.PLAIN_MESSAGE, 3, null, buttons2, buttons2[3]);
- switch (rc2) {
- case 0: // all accounts
- int networth = 0;
- for (Bank acct : accounts) {
- acct.display_details();
- networth += acct.getBal();
- }
- JOptionPane.showMessageDialog(null, "Your account total is: $" + networth);
- case 1: // deposit
- if (accounts.size() == 0)
- JOptionPane.showMessageDialog(null, "You do not have any accounts!");
- else if (accounts.size() == 1) {
- accounts.get(0).deposit(Integer.parseInt(JOptionPane
- .showInputDialog("Enter how many dollars you want to deposit.\n")));
- } else {
- String a = (JOptionPane
- .showInputDialog("Enter the account name to deposit into.\n"));
- for (Bank act : accounts) {
- if (act.getAccountName().equalsIgnoreCase(a))
- act.deposit(Integer.parseInt(JOptionPane.showInputDialog(
- "Enter how many dollars you want to deposit.\n")));
- }
- }
- case 2:
- if (accounts.size() == 0)
- JOptionPane.showMessageDialog(null, "You do not have any accounts!");
- else if (accounts.size() == 1) {
- accounts.get(0).withdraw(Integer.parseInt(JOptionPane
- .showInputDialog("Enter how many dollars you want to withdraw.\n")));
- } else {
- String a = (JOptionPane
- .showInputDialog("Enter the account name to withdraw from.\n"));
- for (Bank act : accounts) {
- if (act.getAccountName().equalsIgnoreCase(a))
- act.deposit(Integer.parseInt(JOptionPane.showInputDialog(
- "Enter how many dollars you want to withdraw.\n")));
- }
- }
- case 3:
- logout = true;
- }
- } while (!logout);
- } else
- JOptionPane.showMessageDialog(null, "Incorrect password");
- }
- }
- if (incun)
- JOptionPane.showMessageDialog(null, "Invalid Username");
- break;
- case 2:
- JOptionPane.showMessageDialog(null, "Thank you for using the JacoBank");
- exit = true;
- break;
- }
- } while (!exit);
- }
- public String getAccountHolderName() {
- return accountHolderName;
- }
- public void setAccountHolderName(String accountHolderName) {
- this.accountHolderName = accountHolderName;
- }
- public String getAccountUsername() {
- return accountUsername;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement