Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help fixing the bugs in my java code, the problem is in bank.java and bankmenu.java in the bankmenu.java all the impelementation are giving

I need help fixing the bugs in my java code, the problem is in bank.java and bankmenu.java in the bankmenu.java all the impelementation are giving me an rerror you can see the pic before you see the code:

image text in transcribed

image text in transcribed

bank.java:

import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable;

import java.util.ArrayList; import java.util.Date; import java.util.InputMismatchException; import java.util.List; import java.util.Scanner;

@SuppressWarnings("serial") public class Bank implements Serializable { Scanner userInput = new Scanner(System.in); String input = ""; String customerInput = ""; long accountNumberInput = 0;

ArrayList accountArray = new ArrayList(); ArrayList customerArray = new ArrayList();

public static void main(String[] args) throws ClassNotFoundException {

Bank b = new Bank(); b.start(); }

public void start() throws ClassNotFoundException {

openFileForReading();

do { displayMenu(); System.out.print("Please select an option: "); input = userInput.next(); switch(input) { case "1": System.out.println("You have chosen to create a new Customer "); createCustomer(); break; case "2": System.out.println("You have chosen to create a new Checking account "); createCheckingAccount(); break; case "3": System.out.println("You have chosen to create a new Gold account "); createGoldAccount(); break; case "4": System.out.println("You have chosen to create a new Regular account "); createRegularAccount(); break; case "5": System.out.println("You have chosen to deposit into your account "); depositIntoAccount(); break; case "6": System.out.println("You have chosen to withdraw from your account "); withdrawFromAccount(); break; case "7": System.out.println("You have chosen to display information for an account "); displayAccountInfo(); break; case "8": System.out.println("You have chosen to remove an account "); removeAccount(); break; case "9": System.out.println("You have chosen to apply account updates "); applyAccountUpdates(); break; case "10": System.out.println("You have chosen to display Bank statistics "); displayBankStatistics(); break; case "11": System.out.println("You have chosen to display all accounts."); displayAllAccounts(); break; case "12": System.out.println("You have chosen to exit the application. Thank you for choosing Bank Co to service your banking needs!"); exit(); break; default: System.out.println("....You have entered an invalid menu option....Please select a valid menu option "); } }while (!input.equals("12")); }

public void displayMenu() { System.out.println("---Bank Menu Options---"); //System.out.print("////////////////////////////////////"); System.out.println(" 1) \tcreate customer"); System.out.println("2) \tcreate new Checking Account"); System.out.println("3) \tcreate new Gold Account"); System.out.println("4) \tcreate new Regular Account"); System.out.println("5) \tdeposit into account"); System.out.println("6) \twithdraw from account"); System.out.println("7) \tdisplay account information"); System.out.println("8) \tremove account"); System.out.println("9) \tapply account updates"); System.out.println("10) \tdisplay Bank statistics"); System.out.println("11) \tdisplay all accounts"); System.out.println("12) \texit");

}

public void createCustomer() {

Customer newPersonal = null; Customer newCommercial = null; customerInput = ""; String customerName; String customerFullName; String customerEmail;

while(!customerInput.equals("1") && !customerInput.equals("2")) { System.out.print(" Is this account for a personal customer(1) or a commercial customer(2): "); customerInput = userInput.next(); }

if (customerInput.equals("1")) {

String customerHomePhone; String customerWorkPhone;

// create Personal customer try { System.out.print("Please input the customer's first name: "); customerName = userInput.next(); customerFullName = customerName; System.out.print("Please input the customer's surname: "); customerName = userInput.next(); customerFullName += " " + customerName; System.out.print(" Please input a valid email: "); customerEmail = userInput.next(); System.out.print(" Please input the customer's home phone number or a cell phone number: "); customerHomePhone = userInput.next(); System.out.print(" Please input the customer's work phone number: "); customerWorkPhone = userInput.next();

//PersonalCustomer(long customerId, String name, String email, String homePhone, String workPhone) newPersonal = new PersonalCustomer(UniqueIDFactory.generateUniqueID(), customerFullName, customerEmail, customerHomePhone, customerWorkPhone); customerArray.add(newPersonal); }catch (RuntimeException e ) { System.err.print("Invalid input"); } } else if(customerInput.equals("2")) {

int customerCreditRating; String contactPersonFirstName; String contactPersonLastName; String contactPerson; String contactPersonPhone;

// create commercial customer try { System.out.print("Please input the customer's first name and surname: "); customerName = userInput.next(); customerFullName = customerName; customerName = userInput.next(); customerFullName += " " + customerName; System.out.print(" Please input a valid email: "); customerEmail = userInput.next(); System.out.print("Please input the customer's credit rating: "); customerCreditRating = userInput.nextInt(); System.out.print("Please input the first and last name of the contact person for the account: "); contactPersonFirstName = userInput.next(); contactPersonLastName = userInput.next(); contactPerson = contactPersonFirstName + contactPersonLastName; System.out.print("Please input the phone number for the contact person: "); contactPersonPhone = userInput.next();

//CommercialCustomer(long customerId, String name, String email, int creditRating, String contactPerson,String contactPersonPhone) newCommercial = new CommercialCustomer(UniqueIDFactory.generateUniqueID(), customerFullName, customerEmail, customerCreditRating, contactPerson, contactPersonPhone); customerArray.add(newCommercial); } catch (RuntimeException e) { System.err.print("Invalid input"); } }

for(Customer c : customerArray) { System.out.println(c); }

while(!input.equals("c")) { System.out.print("Press 'c' to continue: "); input = userInput.next(); } }

public void createCheckingAccount() { double startingBalance = 0; Date newDate = new Date(); String firstName = "", lastName = ""; customerInput = ""; Customer customer = null; boolean customerSelected = false;

if(!customerArray.isEmpty()) {

while(customerSelected == false) { System.out.println("Please enter the full name of the customer that you would like to add to the account"); firstName = userInput.next(); lastName = userInput.next(); customerInput = firstName + " " + lastName; for(Customer c : customerArray) { if(c.getName().equals(customerInput)) { customer = c; customerSelected = true; } } }

// Select customer try { System.out.print(" How much would you like to deposit for the starting balance of your account: "); startingBalance = userInput.nextDouble();

//(String accountNumber, double accountBalance, Customer customer, Date dateCreated) Account chkAcct = new CheckingAccount(UniqueIDFactory.generateUniqueID(),startingBalance, customer, newDate); accountArray.add(chkAcct); System.out.println("Checking account has been successfully created. Your accountNumber is: " + chkAcct.getAccountNumber() + " "); } catch (NumberFormatException n) { System.err.print("Invalid Number Format"); }

}else { System.out.println("There are no customers to make an account with..."); }

while(!input.equals("c")) { System.out.print("Press 'c' to continue: "); input = userInput.next(); } } public void createGoldAccount() {

double startingBalance = 0; Date newDate = new Date(); String firstName = "", lastName = ""; customerInput = ""; Customer customer = null; boolean customerSelected = false;

if(!customerArray.isEmpty()) {

while(customerSelected == false) { System.out.println("Please enter the full name of the customer that you would like to add to the account"); firstName = userInput.next(); lastName = userInput.next(); customerInput = firstName + " " + lastName; for(Customer c : customerArray) { if(c.getName().equals(customerInput)) { customer = c; customerSelected = true; } } } try { System.out.print(" How much would you like to deposit for the starting balance of your account: "); startingBalance = userInput.nextDouble(); }catch(NumberFormatException n) { System.err.print("Invalid number format"); } Account goldAcct = new GoldAccount(UniqueIDFactory.generateUniqueID(),startingBalance, customer, newDate); accountArray.add(goldAcct); System.out.println("Gold account has been successfully created. Your accountNumber is: " + goldAcct.getAccountNumber() + " "); }else { System.out.println("There are no customers to make an account with..."); }

//GoldAccount(long accountNumber, double accountBalance, Customer customer, Date dateCreated, double interestRate) while(!input.equals("c")) { System.out.print("Press 'c' to continue: "); input = userInput.next(); } } public void createRegularAccount() { double startingBalance = 0; Date newDate = new Date(); String firstName = "", lastName = ""; customerInput = ""; Customer customer = null; boolean customerSelected = false;

if(!customerArray.isEmpty()) {

while(customerSelected == false) { System.out.println("Please enter the full name of the customer that you would like to add to the account"); firstName = userInput.next(); lastName = userInput.next(); customerInput = firstName + " " + lastName; for(Customer c : customerArray) { if(c.getName().equals(customerInput)) { customer = c; customerSelected = true; } } }

//RegularAccount(long accountNumber, double accountBalance, Customer customer, Date dateCreated, double interestRate) try { System.out.print(" What is the initial deposit into the account: "); startingBalance = userInput.nextDouble(); } catch(NumberFormatException n) { System.err.print("Invalid Number Format"); } Account regularAcct = new RegularAccount(UniqueIDFactory.generateUniqueID(), startingBalance, customer, newDate); accountArray.add(regularAcct); System.out.println("Regular Account has been created. Your account number is : " + regularAcct.getAccountNumber() + " ");

}else { System.out.println("There are no customers to make an account with..."); }

while(!input.equals("c")) { System.out.print(" Press 'c' to continue: "); input = userInput.next(); }

}

public boolean depositIntoAccount() { double depositAmount = -1; // Amount of money being deposited boolean accountFound = false; //Changes to true if account is found

if(!accountArray.isEmpty()) { System.out.print(" Enter the account number that you would like to deposit into: "); accountNumberInput = userInput.nextLong();

for(Account a : accountArray) { if(a.getAccountNumber() == accountNumberInput) { while(depositAmount

} if (accountFound == false) { System.out.println("The account could not be found."); } } else { System.out.print("There are no accounts to deposit into.");

while(!input.equals("c")) { System.out.print(" Press 'c' to continue: "); input = userInput.next(); } }

return accountFound;

}

public boolean withdrawFromAccount() { double withdrawAmount = -1; boolean accountFound = false;

if(!accountArray.isEmpty()) { System.out.print(" Enter the account number that you would like to withdraw from: "); accountNumberInput = userInput.nextLong();

for(Account a : accountArray) { if(a.getAccountNumber() == accountNumberInput){ while(withdrawAmount

while(!input.equals("c")) { System.out.print(" Press 'c' to continue: "); input = userInput.next(); } } return accountFound; }

public void displayAccountInfo() { boolean accountFound = false;

if(!accountArray.isEmpty()) { System.out.print(" Enter the account number for the account that you would like to view: "); accountNumberInput = userInput.nextLong();

for(Account a : accountArray) { if(a.getAccountNumber() == accountNumberInput) { System.out.println(" Customer Name\t\tAccountNumber\t\tAccount Balance\t\tAccount Email "); System.out.println(a.getCustomer().getName() + "\t\t" + a.getAccountNumber() + "\t\t" + a.getBalance() + "\t\t" + a.getCustomer().getEmail() + " "); accountFound = true; break; }

} if (accountFound == false) { System.out.print("Account could not be found."); } } else { System.out.print("There are no accounts in the bank."); }

while(!input.equals("c")) { System.out.print(" Press 'c' to continue: "); input = userInput.next(); }

}

public void removeAccount() { boolean accountFound = false; long accountNumber = 0;

if(!accountArray.isEmpty()) { try { System.out.print(" Enter the account number that you would like to remove: "); accountNumberInput = userInput.nextLong();

for(int i = 0; i

accountNumber = accountArray.get(i).getAccountNumber();

if(accountNumber == accountNumberInput) { accountFound = true; accountArray.remove(i); accountArray.trimToSize(); System.out.println("Account " + accountNumberInput + " has been removed."); displayAllAccounts(); } } if (accountFound == false) { System.out.println("Account could not be found. "); }

}catch (InputMismatchException e) { System.out.println("Invalid account number"); } }else { System.out.println("There are no accounts in the bank. "); }

while(!input.equals("c")) { System.out.print(" Press 'c' to continue: "); input = userInput.next(); } }

public void applyAccountUpdates() { if(!accountArray.isEmpty()) { for(Account a: accountArray) { if (a instanceof CheckingAccount) { ((CheckingAccount) a).deductFees(); } else if (a instanceof GoldAccount) { ((GoldAccount) a).calculateIntrest(); } else if (a instanceof RegularAccount) { ((RegularAccount) a).calculateIntrest(); } } System.out.print("Account updates applied successfully!"); } else { System.out.print("There are no accounts in the bank."); }

while(!input.equals("c")) { System.out.print(" Press 'c' to continue: "); input = userInput.next(); } }

public void displayBankStatistics() { double totalBalance = 0; double totalCheckingBalance = 0; double totalGoldBalance = 0; double totalRegularBalance = 0; double averageAcctBalance = 0;

int checkingAcctCounter = 0; int goldAcctCounter = 0; int regularAcctCounter = 0; int emptyAcctCounter = 0; double largestAccountBalance = 0; String largestAccount = "";

if(!accountArray.isEmpty()) { System.out.println(" Total balance of all accounts: ");

for(Account a : accountArray) { totalBalance += a.getBalance(); if(a.getBalance() > largestAccountBalance) { largestAccountBalance = a.getBalance(); largestAccount = a.getCustomer().getName(); } }

averageAcctBalance = totalBalance / accountArray.size();

for(Account a : accountArray) { if(a instanceof CheckingAccount) { totalCheckingBalance += a.getBalance(); checkingAcctCounter++; } else if (a instanceof GoldAccount) { totalGoldBalance += a.getBalance(); goldAcctCounter++; } else if (a instanceof RegularAccount) { totalRegularBalance += a.getBalance(); regularAcctCounter++; }

if(a.getBalance() == 0) { emptyAcctCounter++; }

} System.out.println("\tThe total balance of all accounts in the bank is: " + totalBalance); System.out.println("\tThe average account balance is $" + averageAcctBalance + " of all accounts."); System.out.println("\tThe total balance of all Checking accounts in the bank is: $" + totalCheckingBalance); System.out.println("\tThe total balance of all Gold accounts in the bank is: $" + totalGoldBalance); System.out.println("\tThe total balance of all Regular accounts in the bank is: $" + totalRegularBalance); System.out.println("\tThere is a total of: " + checkingAcctCounter + " checking account(s), " + goldAcctCounter + " gold account(s), and " + regularAcctCounter + " regular account(s) in the bank."); System.out.println("\tThere are a total of " + emptyAcctCounter + " empty accounts in the bank."); System.out.println("\tThe customer with the largest balance is: " + largestAccount);

while(!input.equals("c")) { System.out.print(" Press 'c' to continue: "); input = userInput.next(); } } else { System.out.println("There are currently no accounts in the bank.");

while(!input.equals("c")) { System.out.print(" Press 'c' to continue: "); input = userInput.next(); } } }

public void displayAllAccounts() {

while(!input.equals("c")) { if(!accountArray.isEmpty()) { System.out.println(" Customer Information\tAccountNumber");

for(Account a : accountArray) { //System.out.println(a.getCustomer().getName() + "\t\t" + a.getAccountNumber() ); System.out.format("%-14s\t\t%13d ", a.getCustomer().getName(), a.getAccountNumber()); }

} else { System.out.print("There are currently no accounts in the bank."); }

System.out.print(" Press 'c' to continue: "); input = userInput.next(); } }

public void exit() {// throws exception every time

File f = new File("bankdata.ser"); try { ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(f)); output.writeObject(accountArray); System.out.println("Saved"); } catch (IOException ioException) { System.err.println("Error opening file."); //ioException.printStackTrace(); System.out.println(); }

}

@SuppressWarnings("unchecked") public void openFileForReading() throws ClassNotFoundException {

File f = new File("bankdata.ser"); if(f.exists()) {

try { @SuppressWarnings("resource") ObjectInputStream input = new ObjectInputStream(new FileInputStream(f));

accountArray = (ArrayList) input.readObject();

} catch(IOException ioException) { System.err.println("Error opening file."); //ioException.printStackTrace(); System.out.println(); } } } }

____________________________________________

bankmune.java

import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.List;

import javafx.application.Application; import javafx.application.Platform; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.Label; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; import javafx.scene.control.MenuItem; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javafx.scene.input.KeyCombination; import javafx.scene.layout.BorderPane; import javafx.scene.layout.GridPane; import javafx.scene.paint.Color; import javafx.stage.Stage;

public class BankMenu extends Application implements Serializable{

List accountArray = new ArrayList(); List customerArray = new ArrayList();

Label lblPaneTitle = new Label(), lblAccountNumber = new Label("Account Number"), lblaccountBalance = new Label("Account Balance"), lblCustomerName = new Label("Customer Name"), lblEnterName = new Label("Name"), lblEnterEmail = new Label("Email"), lblHomePhone = new Label("Home Phone"), lblWorkPhone = new Label("Work Phone"), lblCreditRating = new Label("Credit Rating"), lblContactPerson = new Label("Contact Person Name"), lblContactPhone = new Label("Contact Person's Phone"), lblTransactionAmount = new Label("Transaction Amount"), lblCreated = new Label("Successfully Created!"), lblNotification = new Label("");

TextField txtAccountNumber = new TextField(), txtAccountBalance = new TextField(), txtCustomerName = new TextField(), txtName = new TextField(), txtEmail = new TextField(), txtHomePhone = new TextField(), txtWorkPhone = new TextField(), txtCreditRating = new TextField(), txtContactPerson = new TextField(), txtContactPhone = new TextField(), txtTransactionAmount = new TextField();

Button btnSubmitChecking = new Button("Create Checking Account"), btnSubmitGold = new Button("Create Gold Account"), btnSubmitPersonalCust = new Button("Create Personal Customer"), btnSubmitCommercialCust = new Button("Create Commercial Customer"), btnSubmitRegular = new Button("Create Regular Account"), btnDeposit = new Button("Deposit into Account"), btnWithdraw = new Button("Withdraw from Account"), btnApplyEOM = new Button("Apply EOM Updates"), btnSearch = new Button("Search for Account"), btnRemove = new Button("Remove an Account"), btnExit = new Button("Exit");

CheckBox cbCommercial = new CheckBox("Commercial");

TextArea textOutputArea = new TextArea(); TextArea textMainOutputArea = new TextArea();

public static void main(String[] args) { launch(args); }

@Override public void start(Stage primaryStage) {

try { openFileForReading(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Scene scene = new Scene(getPane(), 550,350, Color.WHITE); primaryStage.setTitle("Bank"); primaryStage.setScene(scene); primaryStage.show(); }

protected void showPopUp() { Stage popUpWin = new Stage(); Scene popUp = new Scene(getPopUpPane(), 250, 150, Color.WHITE);

popUpWin.setTitle("Success!"); popUpWin.setScene(popUp); popUpWin.show(); }

protected BorderPane getPopUpPane() { BorderPane popUpPane = new BorderPane(); GridPane popUpCenter = new GridPane(); popUpCenter.setPadding(new Insets(11,12,13,14)); popUpCenter.setHgap(5); popUpCenter.setVgap(5); popUpCenter.setAlignment(Pos.CENTER);

popUpCenter.addColumn(2, lblCreated, lblNotification); popUpPane.setCenter(popUpCenter); return popUpPane; }

protected BorderPane getPane() { BorderPane mainPane = new BorderPane(); MenuBar menuBar = new MenuBar(); menuBar.setPrefWidth(300); mainPane.setTop(menuBar);

GridPane centerPane = new GridPane(); centerPane.setPadding(new Insets(11,12,13,14)); centerPane.setHgap(5); centerPane.setVgap(5); centerPane.setAlignment(Pos.CENTER);

// File Menu - Exit Menu fileMenu = new Menu("File"); MenuItem exitMenuItem = new MenuItem("Exit"); exitMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN));

fileMenu.getItems().addAll(exitMenuItem);

// Create Menu - Create Customer, Create Checking Account, Create Gold Account, Create Regular Account

Menu createMenu = new Menu("Create"); MenuItem customerMenu = new MenuItem("Create Customer"); createMenu.getItems().add(customerMenu);

MenuItem checkingMenu = new MenuItem("Create Checking Account"); createMenu.getItems().add(checkingMenu);

MenuItem goldMenu = new MenuItem("Create Gold Account"); createMenu.getItems().add(goldMenu);

MenuItem regularMenu = new MenuItem("Create Regular Account"); createMenu.getItems().add(regularMenu);

// Transactions Menu - Deposit, Withdraw Menu transactionsMenu = new Menu("Transactions"); MenuItem depositMenu = new MenuItem("Deposit"); transactionsMenu.getItems().add(depositMenu);

MenuItem withdrawalMenu = new MenuItem("Withdrawal"); transactionsMenu.getItems().add(withdrawalMenu);

// Maintenance Menu - EoM Update, Remove Menu maintenanceMenu = new Menu("Maintenance"); MenuItem eomMenu = new MenuItem("Apply EoM Updates"); maintenanceMenu.getItems().add(eomMenu);

MenuItem removeMenuItem = new MenuItem("Remove Account"); maintenanceMenu.getItems().add(removeMenuItem);

// Display Menu - Display Account Info, Display All Accounts, Display Bank Stats Menu displayMenu = new Menu("Display"); MenuItem accountInfoMenuItem = new MenuItem("Display Account Info"); displayMenu.getItems().add(accountInfoMenuItem);

MenuItem allAccountsMenuItem = new MenuItem("Display All Accounts"); displayMenu.getItems().add(allAccountsMenuItem);

MenuItem bankStatsMenuItem = new MenuItem("Display Bank Stats"); displayMenu.getItems().add(bankStatsMenuItem);

exitMenuItem.setOnAction(actionEvent -> { exit(); Platform.exit(); });

cbCommercial.setOnAction(actionEvent -> { if(cbCommercial.isSelected()) { mainPane.setCenter(null); centerPane.getChildren().clear();

lblPaneTitle.setText("Enter Customer Information: "); centerPane.add(lblPaneTitle, 0, 0); centerPane.add(lblEnterName, 0, 1); centerPane.add(lblEnterEmail, 0, 2); centerPane.add(lblCreditRating, 0, 3); centerPane.add(lblContactPerson, 0, 4); centerPane.add(lblContactPhone, 0, 5);

centerPane.add(cbCommercial, 1, 0);

centerPane.add(txtName, 1, 1); centerPane.add(txtEmail, 1, 2); centerPane.add(txtCreditRating, 1, 3); centerPane.add(txtContactPerson, 1, 4); centerPane.add(txtContactPhone, 1, 5);

centerPane.add(btnSubmitCommercialCust, 1, 6);

mainPane.setCenter(centerPane); } else { mainPane.setCenter(null); centerPane.getChildren().clear();

lblPaneTitle.setText("Enter Customer Information: "); centerPane.add(lblPaneTitle, 0, 0); centerPane.add(lblEnterName, 0, 1); centerPane.add(lblEnterEmail, 0, 2); centerPane.add(lblHomePhone, 0, 3); centerPane.add(lblWorkPhone, 0, 4);

centerPane.add(cbCommercial, 1, 0);

centerPane.add(txtName, 1, 1); centerPane.add(txtEmail, 1, 2); centerPane.add(txtHomePhone, 1, 3); centerPane.add(txtWorkPhone, 1, 4);

centerPane.add(btnSubmitPersonalCust, 1, 5);

mainPane.setCenter(centerPane); } });

customerMenu.setOnAction(actionEvent -> { mainPane.setCenter(null); centerPane.getChildren().clear();

lblPaneTitle.setText("Enter Customer Information: "); centerPane.add(lblPaneTitle, 0, 0); centerPane.add(lblEnterName, 0, 1); centerPane.add(lblEnterEmail, 0, 2); centerPane.add(lblHomePhone, 0, 3); centerPane.add(lblWorkPhone, 0, 4);

centerPane.add(cbCommercial, 1, 0);

centerPane.add(txtName, 1, 1); centerPane.add(txtEmail, 1, 2); centerPane.add(txtHomePhone, 1, 3); centerPane.add(txtWorkPhone, 1, 4);

centerPane.add(btnSubmitPersonalCust, 1, 5);

mainPane.setCenter(centerPane);

}); //if(!customerArray.isEmpty()) { checkingMenu.setOnAction(actionEvent -> { mainPane.setCenter(null); centerPane.getChildren().clear();

lblPaneTitle.setText("Enter Checking Account Info: "); centerPane.add(lblPaneTitle, 0, 0);

//centerPane.add(lblAccountNumber, 0, 1); centerPane.add(lblaccountBalance, 0, 2); centerPane.add(lblCustomerName, 0, 3);

//centerPane.add(txtAccountNumber, 1, 1); centerPane.add(txtAccountBalance, 1, 2); centerPane.add(txtCustomerName, 1, 3);

centerPane.add(btnSubmitChecking, 1, 4);

mainPane.setCenter(centerPane); });

goldMenu.setOnAction(actionEvent -> { mainPane.setCenter(null); centerPane.getChildren().clear();

lblPaneTitle.setText("Enter Gold Account Information: "); centerPane.add(lblPaneTitle, 0, 0); //centerPane.add(lblAccountNumber, 0, 1); centerPane.add(lblaccountBalance, 0, 2); centerPane.add(lblCustomerName, 0, 3);

//centerPane.add(txtAccountNumber, 1, 1); centerPane.add(txtAccountBalance, 1, 2); centerPane.add(txtCustomerName, 1, 3);

centerPane.add(btnSubmitGold, 1, 4);

mainPane.setCenter(centerPane); });

regularMenu.setOnAction(actionEvent -> { mainPane.setCenter(null); centerPane.getChildren().clear();

lblPaneTitle.setText("Enter Regular Account Information: "); centerPane.add(lblPaneTitle, 0, 0); //centerPane.add(lblAccountNumber, 0, 1); centerPane.add(lblaccountBalance, 0, 2); centerPane.add(lblCustomerName, 0, 3);

//centerPane.add(txtAccountNumber, 1, 1); centerPane.add(txtAccountBalance, 1, 2); centerPane.add(txtCustomerName, 1, 3);

centerPane.add(btnSubmitRegular, 1, 4);

mainPane.setCenter(centerPane); });

depositMenu.setOnAction(actionEvent -> { mainPane.setCenter(null); centerPane.getChildren().clear(); //element, column, row lblPaneTitle.setText("Deposit");

centerPane.add(lblPaneTitle, 0, 0); centerPane.add(lblAccountNumber, 0,1); centerPane.add(txtAccountNumber, 1, 1); centerPane.add(txtTransactionAmount, 1, 2); centerPane.add(lblTransactionAmount, 0, 2); centerPane.add(btnDeposit, 1, 3); centerPane.add(btnExit, 3, 4);

mainPane.setCenter(centerPane); });

withdrawalMenu.setOnAction(actionEvent ->{ mainPane.setCenter(null); centerPane.getChildren().clear(); //element, column, row lblPaneTitle.setText("Withdraw");

centerPane.add(lblPaneTitle, 0, 0); centerPane.add(lblAccountNumber, 0,1); centerPane.add(txtAccountNumber, 1, 1); centerPane.add(txtTransactionAmount, 1, 2); centerPane.add(lblTransactionAmount, 0, 2); centerPane.add(btnWithdraw, 1, 3); centerPane.add(btnExit, 3, 4);

mainPane.setCenter(centerPane); });

eomMenu.setOnAction(actionEvent -> { mainPane.setCenter(null); centerPane.getChildren().clear();

centerPane.add(btnApplyEOM, 0, 0); centerPane.add(btnExit, 0, 1);

mainPane.setCenter(centerPane); });

removeMenuItem.setOnAction(actionEvent -> { mainPane.setCenter(null); centerPane.getChildren().clear();

lblPaneTitle.setText("Remove An Account"); //element, column, row centerPane.add(lblPaneTitle, 0, 0); centerPane.add(lblAccountNumber, 0,1); centerPane.add(txtAccountNumber, 1, 1); centerPane.add(btnRemove, 1, 2);

mainPane.setCenter(centerPane); });

displayMenu.setOnAction(actionEvent -> { mainPane.setCenter(null); centerPane.getChildren().clear();

lblPaneTitle.setText("Display An Account"); //element, column, row centerPane.add(lblPaneTitle, 0, 0); centerPane.add(lblAccountNumber, 0,1); centerPane.add(txtAccountNumber, 1, 1); centerPane.add(btnSearch, 1, 2); textMainOutputArea.setEditable(false); centerPane.add(textMainOutputArea, 0, 3); centerPane.add(btnExit, 1, 4);

mainPane.setCenter(centerPane); }); allAccountsMenuItem.setOnAction(actionEvent -> { mainPane.setCenter(null); centerPane.getChildren().clear();

lblPaneTitle.setText("Display All Accounts"); //element, column, row centerPane.add(lblPaneTitle, 0, 0); textOutputArea.setEditable(false); centerPane.add(textOutputArea, 0, 1); centerPane.add(btnExit, 1, 2);

for(Account a : accountArray) {

textOutputArea.appendText(a.getCustomer().getName() + "\t\t\t" + a.getAccountNumber());

}

mainPane.setCenter(centerPane); });

bankStatsMenuItem.setOnAction(actionEvent -> { mainPane.setCenter(null); centerPane.getChildren().clear();

lblPaneTitle.setText("Display Bank Statistics"); centerPane.add(lblPaneTitle, 0, 0); centerPane.add(textOutputArea, 0, 1); centerPane.add(btnExit, 1, 2);

double totalBalance = 0; double totalCheckingBalance = 0; double totalGoldBalance = 0; double totalRegularBalance = 0; double averageAcctBalance = 0;

int checkingAcctCounter = 0; int goldAcctCounter = 0; int regularAcctCounter = 0; int emptyAcctCounter = 0; double largestAccountBalance = 0; String largestAccount = "";

if(!accountArray.isEmpty()) { System.out.println(" Total balance of all accounts: ");

for(Account a : accountArray) { totalBalance += a.getAccountBalance(); if(a.getAccountBalance() > largestAccountBalance) { largestAccountBalance = a.getAccountBalance(); largestAccount = a.getCustomer().getName(); } }

averageAcctBalance = totalBalance / accountArray.size();

for(Account a : accountArray) { if(a instanceof CheckingAccount) { totalCheckingBalance += a.getAccountBalance(); checkingAcctCounter++; } else if (a instanceof GoldAccount) { totalGoldBalance += a.getAccountBalance(); goldAcctCounter++; } else if (a instanceof RegularAccount) { totalRegularBalance += a.getAccountBalance(); regularAcctCounter++; }

if(a.getAccountBalance() == 0) { emptyAcctCounter++; }

} textOutputArea.appendText("\tThe total balance of all accounts in the bank is: " + totalBalance + " "); textOutputArea.appendText("\tThe average account balance is $" + averageAcctBalance + " of all accounts. "); textOutputArea.appendText("\tThe total balance of all Checking accounts in the bank is: $" + totalCheckingBalance + " "); textOutputArea.appendText("\tThe total balance of all Gold accounts in the bank is: $" + totalGoldBalance + " "); textOutputArea.appendText("\tThe total balance of all Regular accounts in the bank is: $" + totalRegularBalance + " "); textOutputArea.appendText("\tThere is a total of: " + checkingAcctCounter + " checking account(s), " + goldAcctCounter + " gold account(s), \t\t and " + regularAcctCounter + " regular account(s) in the bank. "); textOutputArea.appendText("\tThere are a total of " + emptyAcctCounter + " empty accounts in the bank. "); textOutputArea.appendText("\tThe customer with the largest balance is: " + largestAccount + " "); }

mainPane.setCenter(centerPane); }); //}

btnSubmitPersonalCust.setOnAction(actionEvent -> {

String customerName = txtName.getText(); String customerEmail = txtEmail.getText(); String customerHomePhone = txtHomePhone.getText(); String customerWorkPhone = txtWorkPhone.getText();

Customer newPersonal = new PersonalCustomer(UniqueIDFactory.generateUniqueID(), customerName, customerEmail, customerHomePhone, customerWorkPhone); customerArray.add(newPersonal);

txtName.clear(); txtEmail.clear(); txtHomePhone.clear(); txtWorkPhone.clear();

centerPane.getChildren().clear(); mainPane.setCenter(centerPane);

lblNotification.setText("Your ID is: " + Long.toString(newPersonal.getCustomerId())); showPopUp(); });

btnSubmitCommercialCust.setOnAction(actionEvent ->{

String customerFullName = txtName.getText(); String customerEmail = txtEmail.getText(); int customerCreditRating = Integer.parseInt(txtCreditRating.getText()); String contactPerson = txtContactPerson.getText(); String contactPersonPhone = txtContactPhone.getText();

Customer newCommercial = new CommercialCustomer(UniqueIDFactory.generateUniqueID(), customerFullName, customerEmail, customerCreditRating, contactPerson, contactPersonPhone); customerArray.add(newCommercial);

txtName.clear(); txtEmail.clear(); txtCreditRating.clear(); txtContactPerson.clear(); txtContactPhone.clear();

centerPane.getChildren().clear(); mainPane.setCenter(centerPane); });

btnSubmitChecking.setOnAction(actionEvent -> { Date newDate = new Date(); double startingBalance = Double.parseDouble(txtAccountBalance.getText());

String customerInput = txtCustomerName.getText(); boolean customerSelected = false; Customer customer = null;

for(Customer c : customerArray) {

System.out.println(c); if(c.getName().equals(customerInput)) { customer = c; customerSelected = true; } }

if(customerSelected) { Account chkAcct = new CheckingAccount(UniqueIDFactory.generateUniqueID(),startingBalance, customer, newDate); accountArray.add(chkAcct); System.out.println("Checking account has been successfully created. Your accountNumber is: " + chkAcct.getAccountNumber() + " "); }else System.out.println("Customer could not be found");

txtCustomerName.clear(); txtAccountBalance.clear();

centerPane.getChildren().clear(); mainPane.setCenter(centerPane); });

btnSubmitGold.setOnAction(actionEvent -> { Date newDate = new Date();

double startingBalance = Double.parseDouble(txtAccountBalance.getText());

String customerInput = txtCustomerName.toString(); Customer customer = null;

for(Customer c : customerArray) { if(c.getName().equals(customerInput)) { customer = c; //customerSelected = true; } }

Account goldAcct = new GoldAccount(UniqueIDFactory.generateUniqueID(),startingBalance, customer, newDate); accountArray.add(goldAcct); System.out.println("Gold account has been successfully created. Your accountNumber is: " + goldAcct.getAccountNumber() + " ");

txtCustomerName.clear(); txtAccountBalance.clear();

centerPane.getChildren().clear(); mainPane.setCenter(centerPane); });

btnSubmitRegular.setOnAction(actionEvent ->{ Date newDate = new Date();

double startingBalance = Double.parseDouble(txtAccountBalance.getText());

String customerInput = txtCustomerName.toString(); Customer customer = null;

for(Customer c : customerArray) { if(c.getName().equals(customerInput)) { customer = c; //customerSelected = true; } }

Account regularAcct = new RegularAccount(UniqueIDFactory.generateUniqueID(), startingBalance, customer, newDate); accountArray.add(regularAcct); System.out.println("Regular Account has been created. Your account number is : " + regularAcct.getAccountNumber() + " ");

txtCustomerName.clear(); txtAccountBalance.clear();

centerPane.getChildren().clear(); mainPane.setCenter(centerPane); });

btnDeposit.setOnAction(actionEvent -> {

long accountNumberInput = Long.parseLong(txtAccountNumber.getText()); double depositAmount = Double.parseDouble(txtTransactionAmount.getText());

for(Account a : accountArray) { if(a.getAccountNumber() == accountNumberInput) { a.deposit(depositAmount); System.out.println("Success"); } }

txtAccountNumber.clear(); txtTransactionAmount.clear();

centerPane.getChildren().clear(); mainPane.setCenter(centerPane); });

btnWithdraw.setOnAction(actionEvent -> { long accountNumberInput = Long.parseLong(txtAccountNumber.getText()); double withdrawAmount = Double.parseDouble(txtTransactionAmount.getText());

for(Account a : accountArray) { if(a.getAccountNumber() == accountNumberInput) { a.withdraw(withdrawAmount); System.out.println("Success"); } }

txtAccountNumber.clear(); txtTransactionAmount.clear();

centerPane.getChildren().clear(); mainPane.setCenter(centerPane); });

btnSearch.setOnAction(actionEvent -> { long accountNumberInput = Long.parseLong(txtAccountNumber.getText()); textMainOutputArea.setText("Customer Name\t\tAccount Number\t\tAccount Balance " );

for(Account a : accountArray) { if(a.getAccountNumber() == accountNumberInput) { textMainOutputArea.appendText(a.getCustomer().getName() + "\t\t\t\t\t" + a.getAccountNumber() + "\t\t\t" + a.getAccountBalance());

} } });

btnRemove.setOnAction(actionEvent -> { long accountNumber;

long accountNumberInput = Long.parseLong(txtAccountNumber.getText());

for(int i = 0; i

accountNumber = accountArray.get(i).getAccountNumber();

if(accountNumber == accountNumberInput) { accountArray.remove(i); ((ArrayList) accountArray).trimToSize(); System.out.println("Account " + accountNumberInput + " has been removed.");

} }

});

btnApplyEOM.setOnAction(actionEvent -> { for(Account a: accountArray) { if (a instanceof CheckingAccount) { ((CheckingAccount) a).deductFees(); } else if (a instanceof GoldAccount) { ((GoldAccount) a).calculateInterest(); } else if (a instanceof RegularAccount) { ((RegularAccount) a).calculateInterest(); } }

centerPane.getChildren().clear(); mainPane.setCenter(centerPane);

});

btnExit.setOnAction(actionEvent -> {

textOutputArea.clear(); textMainOutputArea.clear(); txtAccountNumber.clear();

centerPane.getChildren().clear(); mainPane.setCenter(centerPane);

});

menuBar.getMenus().addAll(fileMenu, createMenu, transactionsMenu, maintenanceMenu, displayMenu);

return mainPane; }

public void openFileForReading() throws ClassNotFoundException {

File f = new File("bankdata.ser"); if(f.exists()) {

try { ObjectInputStream input = new ObjectInputStream(new FileInputStream(f));

accountArray = (ArrayList) input.readObject();

} catch(IOException ioException) { System.err.println("Error opening file."); //ioException.printStackTrace(); System.out.println(); } } } public void exit() {

File f = new File("bankdata.ser"); try { ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(f)); output.writeObject(accountArray); System.out.println("Saved"); } catch (IOException ioException) { System.err.println("Error opening file."); //ioException.printStackTrace(); System.out.println(); }

}

}

_______________________________

/*

* Account.java

*

* This is a super class for other accounts

* to inherit. A generic account cannot be

* created and is therefore abstract. Also, if we want

* to force future functionality to be implemented

* by different account types, abstract will allow for this.

*/

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Calendar;

public abstract class Account{

// All accounts will have the following attributes

// Declaring these protected allows for subclass access

protected long accountNumber; // used to show the account number for the customer

protected double balance; // used to show the balance in the account

protected Calendar dateOpened; // used to show the date opened

protected Customer customer; // Used to tie the account to a customer

/**

*

* Account constructor requiring five

* attributes to create. Subclasses will be forced to call

* this constructor and set these required values.

*/

public Account(long accountNumber, double balance, Calendar dateOpened, Customer customer){

this.accountNumber = accountNumber;

this.balance = balance;

this.dateOpened = dateOpened;

this.customer = customer;

}

/**

*

* makeDeposit is used to add funds to an account

* Note this method assumes valid data.

*/

public void makeDeposit(double depositAmount) {

balance += depositAmount;

}

/**

*

* makeWithdrawal is used to withdraw funds from an account

* Note this method assumes valid data.

* Assumes no further action if there is an overdraft

*/

public void makeWithdrawal(double withdrawalAmount) {

balance -= withdrawalAmount;

}

// these methods are abstract because we want to implement them in the supclass

public abstract void deducteFee(double fee);

public abstract void calculateIntrest();

public long getAccountNumber(){

return accountNumber;

}

public void setAccountNumber(long accountNumber){

this.accountNumber = accountNumber;

}

public double getBalance(){

return balance;

}

public void setBalance(double balance){

this.balance = balance;

}

public Calendar getDateOpened(){

return dateOpened;

}

public void setDateOpened(Calendar dateOpened){

this.dateOpened = dateOpened;

}

public Customer getCustomer(){

return customer;

}

public void setCustomer(Customer customer){

this.customer = customer;

}

/**

*

* String representation of this object

*/

public String toString() {

String output = "";

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

output += " Account Number: " + this.accountNumber;

output += " Account Balance: " + this.balance;

output += " Account Date open: " + dateFormat.format(dateOpened.getTime());

output += " Customer Account: " + this.customer;

return output;

}

}

__________________________

/*

* CheckingAccount.java

* A specialized account representing a checking

* account

*

*/

import java.util.Calendar;

public class CheckingAccount extends Account {

private int transactionFee = 3;

/**

*

* Checking account constructor requiring five

* attributes to create

*

*/

public CheckingAccount(long accountNumber, double balance, Calendar dateOpened,Customer customer){

// Call superclass constructor

super(accountNumber, balance, dateOpened, customer);

}

// CheckingAccount have interest free in the first two month.

// it charge 3$ for every transaction(deposit/withdrawal)

public void deducteFee(double fee){

fee = balance - transactionFee;

}

public void calculateIntrest(){

balance = balance + balance * transactionFee;

}

/**

*

* String representation of this object

*

*/

public String toString(){

String output = super.toString();

return output;

}

}

_________________________

/*

* Customer.java

*

* This is a super class for other customers

* to inherit. A generic customer cannot be

* created and is therefore abstract. Also, if we want

* to force future functionality to be implemented

* by different customer types, abstract will allow for this.

*/

public class Customer {

// All customers will have the following attributes

// Declaring these protected allows for subclass access

protected String customerID;

protected String name;

protected String address;

protected String phoneNumber;

protected String email;

public Customer(){

this.customerID = "";

this.name = "";

this.address = "";

this.phoneNumber = "";

this.email = "";

}

public Customer (String customerID,String name,String address,String phoneNumber, String email){

this.customerID = customerID;

this.name = name;

this.address = address;

this.phoneNumber = phoneNumber;

this.email = email;

}

public void setCustomerID(String customerID){

this.customerID = customerID;

}

public String getCustomerID(){

return customerID;

}

public void setName(String name){

this.name = name;

}

public String getName(){

return name;

}

public void setAddress(String address){

this.address = address;

}

public String getAddress(){

return address;

}

public void setPhoneNumber(String phoneNumber){

this.phoneNumber = phoneNumber;

}

public String getPhoneNumber(){

return phoneNumber;

}

//String representation of this object

public String toString(){

String output = "";

output += " Customer ID: " + this.customerID;

output += " Customer Name: " + this.name;

output += " Customer Address: " + this.address;

output += " Customer Phone Number: " + this.phoneNumber;

return output;

}

public void setEmai(String email){

this.email = email;

}

public String getEmail() {

return email;

}

}

________________________

/*

* GoldAccount.java

* A specialized account representing a gold

* account

*

*/

import java.util.Calendar;

public class GoldAccount extends Account {

// GoldAccount will have the following attributes

// Declaring these private secures the attributes

private double fixedRate;

/**

*

* gold account constructor requiring five

* attributes to create

*

*/

public GoldAccount(long accountNumber, double balance, Calendar dateOpened, Customer customer) {

// Call superclass constructor

super(accountNumber, balance, dateOpened, customer);

}

//GoldAccount have to deductFee 10$

public void deducteFee(double fee) {

fee = balance = balance -10;

}

//GoldAccount have to calculateIntrest

public void calculateIntrest() {

balance = (balance + fixedRate )/ 100;

}

/**

*

* String representation of this object

*

*/

public String toString(){

String output = super.toString();

return output;

}

}

_______________________________

/*

* RegularAccount.java

* A specialized account representing a Regular

* account

*

*/

import java.util.Calendar;

public class RegularAccount extends Account {

// RegulareAccount will have the following attributes

// Declaring these private secures the attributes

private double fixedRate;

/**

*

* regular account constructor requiring five

* attributes to create

*

*/

public RegularAccount(long accountNumber, double balance, Calendar dateOpened, Customer customer) {

// Call superclass constructor

super(accountNumber, balance, dateOpened, customer);

}

//RegularAccount have to deductFee 10$

public void deducteFee(double fee) {

fee = balance = balance -10;

}

//RegularAccount have to calculateIntrest

public void calculateIntrest() {

balance = (balance + fixedRate )/ 100;

}

/**

*

* String representation of this object

*

*/

public String toString(){

String output = super.toString();

return output;

}

}

_____________________________

import java.io.Serializable; import java.util.Calendar;

@SuppressWarnings("serial") public class UniqueIDFactory implements Serializable {

public static long generateUniqueID(){

return Calendar.getInstance().getTimeInMillis();

}

}

workspace - Java - bankprogram/src/BankMenu,java - Eclipse File Edit Source Refactor Navigate Search Project Run Window Help Quick Access| . | Package Explorer X BankMenu.java 3 B ) Welcome X (Objects, Classes, and Aggregation Get an overview of the features 13 import Javafx.application. Platform 14 1mport avatx.geometxy Inaeta: 15 import ??src (default package) ?Account-Java Tutorials Go through tutorials 17 import ?avatx.scene.contro1 :Button; 18 1mport avatx.acene.sontrel.SheckBox Menu: 20 import javafx.sssns 21 import ?avatx.scene.control. MenuBar; 22 1mport ayati, scene ' control' MenuItem; 23 import 24 import javafx.sssns 25 import javafx.scene.input KeyCode: 26 Import ayati, scene 'input, XeXCodeCombination; 27 import 28 import iavafx.sssns.lavgut BozdsxPans: 29 import ?avatx.scene.layout .GridPane; 30 1mport avatx.ecene.paint.Saler: Try out the samples I> D Customer-Java GoldAccountjava DRegularAccount.jeva UniquelDFactory.java What's New Find out what is new D JRE System Library JavaSE-1.8) ? DSLab7 EXAM3 eeclipse ? Lab2Tim Lab6 ? LAB7 32 33 publio olass BankMenu extends Application implements Serializablef 34 35 L?5t(Account) accountArray-new ArrayList(); 36 List customerArraynew ArrayList0 37 38 Practcing b Project2018 ? Project2DS DProjectDs Updates Available Declaration ProblemsJavadoc 109 TaskCh2 Updates are aveilable for your software Click to review and install updates Set up Reminder options 17 s, 0 others (Filter matched 117 of 126 items) Writable Smart Insert 11:36 6/2018

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions