Question
I need to complete a bank program using javaFX that reads from a file. Below are the Insturctions and the classes that are already completed.
I need to complete a bank program using javaFX that reads from a file. Below are the Insturctions and the classes that are already completed. The classes that I already have are in the bank.model package. The classes that I need to do will have to be in the bank.view package.
INSTRUCTIONS:
Its time to do a little practice with FX user interfaces. For this assignment, we will add a GUI to the Bank application we worked on for Program 1. As before, we will load in accounts and transactions from a csv file. This will be done in the start method prior to showing our UI. There is a starting Bank project that you may use, or you may continue with the project you designed for Program 1.
For a starting grade of C: (80)
You should have a single Transaction window that essentially acts as an ATM. There will be a text field where you type in the account number. (Well ignore your PIN.) Once an account number is entered, the user should be able to press a button, Load Account. At this point, the account number, the type of account (Savings or Checking) and the current balance should be displayed. You may do this using Text or TextArea controls, but make certain it looks nice. If the account is not found, the user should be informed. (Note this may mean you will need to search for both checking and saving accounts, depending on your Bank. The Bank project that is part of this assignment has a findAccountByNum method that will return either type.) Once the account information is displayed, the user should be able to type in an amount and press either a Deposit or Withdraw button. The field to type in the amount and the two buttons should be disabled until the account has been selected; similarly, once an account has been successfully selected, the account number text field and the Load Account button should be disabled. When the deposit or withdrawal is made, the new balance for the account should replace the old one. If the transaction fails, notify the user. The user should be able to perform as many deposits and withdrawals as desired without entering a new account number. At any point after the user has been shown their account they should be able to press a Done button. The application will clear all account specific information, and disable the amount field and the Deposit and Withdraw buttons. The window should then be able to accept a new account number.
Note 1: all of the above can be done in a single window. The only exception is when the user is informed of an error or when the program thanks them for their business; then you may use an Alert window.
Note 2: Enabling and disabling the controls can be tedious, consider doing this in a method.
Beyond a grade of C:
For the following additions, you must first create a new initial window. Each of the additions that follow will require that you add the specified controls to this initial window. You may do any combination of the additions with the exception that you must do either A1 or A2, but not both.
(A) Worth 2 OR 7 points
You must do one, but only one, of these two options. Note, for both A1 and A2, the initial window should not allow a user to open multiple accounts, i.e. the user should not be able to select more than one account at a time. If an account is already being shown, that window will be raised showing the current account (i.e. the account already being displayed in the Transaction window). If it is not, the window will be brought up with the newly selected account active. There should be only one Transaction window object ever created by the program. That window will be populated as needed.
(A1) Worth 3 points
To the Startup window, add a button that brings up the Transaction window described above. Make certain there is only one instance as described in the above paragraph.
(A2) Worth up to 7 points
To the Startup window add a ComboBox that lists all of the accounts as well as a Show Account button. Once the user has selected an account, the Show Account button should open a separate Transaction window displaying information for the selected account. The window that is opened should be just like the Transaction window described above, with these exceptions: there should be no way to select a new account number (which means the text field and the Load Account button should be removed). Also, the Done button should dismiss the window. Make certain there is only one instance as described in the above paragraph.
(B) Worth up to 9 Points
Add a new button Open Account button to the Startup window to create an account. Pressing this button will display a new Account Creation window that asks for a type (radio button), account number and opening balance. This window should have OK and Cancel buttons. When the user hits OK, the new account will be opened in the Bank and the window will be dismissed; hitting the Cancel button will dismiss the window. Once created (make certain you check whether the account was actually added; display an Alert if it is not) the new account should appear in your ComboBox that shows all of the account numbers. Essentially, you want to reload the array list. Make certain you get the list from the Bank. (Do not save the account number and add it directly.) You should allow the creation of only a single account at one time. If the Create Account window is already showing, raise it to the front so the user can see it.
(C) Worth up to 8 Points
Add a Transfer Funds button to the Startup window that brings up a Transfer window. This button will display a window with a means to select the two and from accounts, a place to enter the amount, and some sort of OK button. If the transfer is unsuccessful, the user will be notified and the window will remain. If it successful, the window will be dismissed. You may allow multiple Transfer windows just as you did Transaction windows. Changes in the accounts affected by the transfer do not need to show up in the Transaction window if it happens to be open, but if that window is closed and reopened, the changes will be seen.
Account.java class:
import java.util.ArrayList; import java.util.Collections; import java.util.List;
public class Account { static public enum AccountType { CHECKING, SAVINGS } //type of object array list will hold inside arrows private static ArrayList
public double getBalance() { return balance; }
public AccountType getAccountType() { return accountType; }
public String getAccountNumber() { return accountNumber; }
public Account(String accountNumber, double balance, AccountType type) { this.accountNumber = accountNumber; this.balance = balance; this.accountType = type; Transaction o = new Transaction(Transaction.Type.OPEN_ACCNT, balance, balance); transactions.add(o); }
public boolean deposit(double amount) { balance += amount; Transaction t = new Transaction(Transaction.Type.DEPOSIT,amount, balance); transactions.add(t); return true; }
public boolean withdraw(double amount) { if (amount <= balance) { balance -= amount; Transaction w =new Transaction(Transaction.Type.WITHDRAW, amount, balance); transactions.add(w); return true; } else { return false; } } public boolean serviceFee(double amount) { if (balance >= amount) { balance-=amount; Transaction s = new Transaction(Transaction.Type.SERV_FEE, amount, balance); transactions.add(s); } return true; } public List
Bank.java class:
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.Scanner;
public class Bank { private static Bank instance = new Bank();
private ArrayList
/** * Gets the Singleton Bank instance * @return Returns the singleton Bank instance */ public static Bank getInstance() { return instance; }
/** * Open a new savings account and place it in the list of bank accounts. * * @param accntNum the number of the new account * @param initialBal the initial balance * @return Returns true if an account is created; false if the account already exists or the balance is invalid */ public boolean openSavingsAccount(String accntNum, double initialBal) { if (findAccountByNum(accntNum) != null || initialBal < 0) { return false; }
SavingsAccount savings = new SavingsAccount(accntNum, initialBal);
return accounts.add(savings); }
/** * Open a new checking account and place it in the list of bank accounts. * * @param accntNum the number of the new account * @param initialBal the initial balance * @return Returns true if an account is created; false if the account already exists or the balance is invalid */ public boolean openCheckingAccount(String accntNum, double initialBal, double minBalance) { if (findAccountByNum(accntNum) != null || initialBal < 0) { return false; }
CheckingAccount checking = new CheckingAccount(accntNum, initialBal);
return accounts.add(checking); } /** * Finds the account specified by the given account number * @param accntNum the number of the account to be found * @return Returns the account matching the number if found; null if the account is not found */ public Account findAccountByNum(String accntNum) { Account acnt = null; Optional
/** * Transfers the specified amount from the fromAccount to the toAccount. This method can fail if either * of the account numbers is invalid, or if the fromAccount has insufficient funds to make the transfer. * @param fromAccountNum The account number of the account from which the money is to be withdrawn. * @param toAccountNum The account number of the account to which the money is to be deposited. * @param amount The amount to be transfered. * @return Returns true if the transfer was successful, false otherwise */ public boolean makeTransfer(String fromAccountNum, String toAccountNum, double amount) { Account fromAccnt; Account toAccnt;
fromAccnt = findAccountByNum(fromAccountNum); toAccnt = findAccountByNum(toAccountNum);
if (fromAccnt == null || toAccnt == null) { return false; }
if (fromAccnt.withdraw(amount)) { toAccnt.deposit(amount); return true; } else { return false; } } /** * Pulls all of the account numbers from the accounts and returns them as a list of strings. * @return The list of account numbers. */ public List
while (input.hasNext()) { String line = input.nextLine(); // creates an string array called fields and populates each item // splitting by comma. String[] fields = line.split(","); // System.out.println("number of fields: " + fields.length); // first field and first character switch (fields[0].charAt(0)) { case 'O': case 'o': { double minBalance = 0; // open a new account String accntNum = fields[1]; String type = fields[2]; double initialBalance = Double.parseDouble(fields[3]); if (fields.length == 5) { minBalance = Double.parseDouble(fields[4]); }
createAccount(accntNum, type, initialBalance, minBalance); } break; case 'D': case 'd': { // deposit into an account String accntNum = fields[1]; String type = fields[2]; double amount = Double.parseDouble(fields[3]);
Account account = findAccountByNum(accntNum); account.deposit(amount);
} break; case 'W': case 'w': { String accntNum = fields[1]; String type = fields[2]; double amount = Double.parseDouble(fields[3]); Account account = findAccountByNum(accntNum); account.withdraw(amount); } break; case 'T': case 't': { String fromAccount = fields[1]; String toAccount = fields[2]; double amount = Double.parseDouble(fields[3]); makeTransfer(fromAccount, toAccount, amount); } break; default: { System.out.println("Does not meet requirements");
}
} } input.close(); }
private void createAccount(String accntNum, String type, double initialBalance, double minBalance) { switch (type.charAt(0)) { case 's': case 'S': { openSavingsAccount(accntNum, initialBalance); } break;
case 'c': case 'C': { openCheckingAccount(accntNum, initialBalance, minBalance); } break; } } }
CheckingAccount.java class:
public class CheckingAccount extends Account { private final double MIN_BALANCE = 100.00; private final double SERV_FEE = .13;
public CheckingAccount(String number, double initialBalance) { super(number, initialBalance,Account.AccountType.CHECKING); }
public boolean withdraw(double amount) { boolean result = super.withdraw(amount); if (result) { if (super.getBalance() < MIN_BALANCE) { super.serviceFee(SERV_FEE); } }
return result; } }
SavingsAccount.java class:
public class SavingsAccount extends Account { private final int MAX_WITHDRAWALS=7; private int numWithdrawals=0; private final double SERV_FEE=.23; public SavingsAccount(String number, double initialBalance) { super(number, initialBalance, Account.AccountType.SAVINGS); } @Override public boolean withdraw(double amount) { boolean result=false; result=super.withdraw(amount); if(result) { numWithdrawals++; if(numWithdrawals>MAX_WITHDRAWALS) { super.serviceFee(SERV_FEE); } } return result; }
public void resetWithdrawalCount() { numWithdrawals=0; } }
Transactions.java class:
public class Transaction { static public enum Type { OPEN_ACCNT, DEPOSIT, WITHDRAW, SERV_FEE } private Type transType; private double transAmount=0; private double transBalance=0; public Transaction (Type type, double amount, double balance) { transType= type; transAmount=amount; transBalance=balance; }
public Type getType() { return transType; }
public double getTransAmount() { return transAmount; } public double getBalance() { return transBalance; } }
Here is the file that it needs to read from:
Transactions.csv file:
O | ABC12130 | S | 25 |
O | SAV12133 | S | 25 |
O | ABC12135 | C | 25 |
O | SAV12136 | S | 50 |
O | NAV12137 | S | 25 |
O | CHK12139 | C | 50 |
W | NAV12137 | S | 18.78 |
W | ABC12130 | S | 17.07 |
D | ABC12135 | C | 136.87 |
D | CHK12139 | C | 193.81 |
D | SAV12136 | S | 76.3 |
O | SAV12132 | S | 200 |
W | SAV12132 | S | 80.91 |
O | SCF12134 | C | 100 |
W | SCF12134 | C | 65 |
W | ABC12130 | S | 3.55 |
W | SAV12132 | S | 2.9 |
D | NAV12137 | S | 125.42 |
O | CHK12131 | C | 50 |
W | CHK12131 | C | 12.23 |
W | SCF12134 | C | 135 |
D | SCF12134 | C | 157.16 |
O | CHK12138 | C | 100 |
W | CHK12138 | C | 90.44 |
W | NAV12137 | S | 3.04 |
W | CHK12138 | C | 9.35 |
W | ABC12135 | C | 103.12 |
D | ABC12130 | S | 287.56 |
W | SCF12134 | C | 40.72 |
D | CHK12131 | C | 46.12 |
D | SCF12134 | C | 44.81 |
D | ABC12135 | C | 181.67 |
W | NAV12137 | S | 49.17 |
D | ABC12130 | S | 167.27 |
D | CHK12131 | C | 197.06 |
D | SCF12134 | C | 222.67 |
W | SCF12134 | C | 311.74 |
D | SAV12133 | S | 228.18 |
W | SAV12136 | S | 54.24 |
W | CHK12131 | C | 41.47 |
W | NAV12137 | S | 27.97 |
D | NAV12137 | S | 182.73 |
W | CHK12131 | C | 226.57 |
W | SAV12136 | S | 4.44 |
W | SAV12132 | S | 15.45 |
W | SAV12136 | S | 47.88 |
D | SAV12136 | S | 96.25 |
D | NAV12137 | S | 258.67 |
D | CHK12138 | C | 237.18 |
D | CHK12131 | C | 39.69 |
W | SAV12136 | S | 23.46 |
D | SAV12132 | S | 150.97 |
W | CHK12139 | C | 77.86 |
W | SAV12136 | S | 21.86 |
W | SAV12136 | S | 29.51 |
W | CHK12131 | C | 16.01 |
W | SAV12132 | S | 29.5 |
D | ABC12135 | C | 224.73 |
D | ABC12135 | C | 213.83 |
D | SAV12136 | S | 281.42 |
D | CHK12138 | C | 179.4 |
W | CHK12131 | C | 17.75 |
W | CHK12138 | C | 397.98 |
W | SAV12132 | S | 31.75 |
D | SCF12134 | C | 296.57 |
D | ABC12130 | S | 221.12 |
W | CHK12138 | C | 17.62 |
D | CHK12139 | C | 12.38 |
W | SAV12132 | S | 42.63 |
D | CHK12131 | C | 132.49 |
W | SCF12134 | C | 294.44 |
W | NAV12137 | S | 234.67 |
D | ABC12135 | C | 21.44 |
D | SCF12134 | C | 295.15 |
W | CHK12139 | C | 71.65 |
W | SCF12134 | C | 273.31 |
W | SAV12133 | S | 226.2 |
W | NAV12137 | S | 202.87 |
D | CHK12138 | C | 106.98 |
D | SAV12133 | S | 51.12 |
W | ABC12130 | S | 618.64 |
D | SAV12133 | S | 180.39 |
D | CHK12139 | C | 130.77 |
D | SAV12133 | S | 14.96 |
W | CHK12131 | C | 25.28 |
D | SAV12133 | S | 116.43 |
D | CHK12138 | C | 142.2 |
W | ABC12130 | S | 22.15 |
W | SAV12136 | S | 314.12 |
W | NAV12137 | S | 24.68 |
D | CHK12131 | C | 138.33 |
D | SAV12133 | S | 168.65 |
D | SAV12136 | S | 200.91 |
D | SAV12133 | S | 22.67 |
W | CHK12139 | C | 162.32 |
W | NAV12137 | S | 18.28 |
D | SAV12133 | S | 47.87 |
W | CHK12131 | C | 248 |
D | CHK12131 | C | 159.55 |
D | ABC12135 | C | 36.72 |
W | SAV12132 | S | 23.82 |
W | CHK12131 | C | 24.18 |
W | CHK12131 | C | 146.95 |
D | ABC12130 | S | 285.19 |
W | CHK12138 | C | 13.38 |
W | CHK12139 | C | 59.09 |
W | ABC12130 | S | 23.59 |
D | CHK12139 | C | 95.66 |
W | SCF12134 | C | 94.64 |
T | SAV12133 | NAV12137 | 100 |
T | SCF12134 | CHK12131 | 100 |
Any help would be greatly appreciated as I am stuck on this and don't know what to do. Like I said the new classes that need to be created need to be created in the bank.view package.
Thank you in advance.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started