Hello i need to fix some major problem in my java code please: First of all when
ID: 3916619 • Letter: H
Question
Hello i need to fix some major problem in my java code please:
First of all when you press to creat customer it just give you a one choice of commerical!! it should also give you another choise of personal ( can you do that please )
Second problem as shown in the pictuser when you creat a customer it not giving you and ID number !!
Third problem when you try to do a checking account or any account it not giving you any action
Here is my code you can download it from this link below:
https://file.fm/u/wn22jw6a
Thank you
Explanation / Answer
updated files : ----------->>>>>>>>
BankMenu.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;
@SuppressWarnings("serial")
public class BankMenu extends Application implements Serializable{
List<Account> accountArray = new ArrayList<Account>();
List<Customer> customerArray = new ArrayList<Customer>();
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");
CheckBox cbPersonal = new CheckBox("Personal");
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();
});
cbPersonal.setOnAction(actionEvent ->{
if(cbPersonal.isSelected()){
cbCommercial.setSelected(false);
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(cbPersonal,2,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);
}
});
cbCommercial.setOnAction(actionEvent -> {
if(cbCommercial.isSelected()) {
cbPersonal.setSelected(false);
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(cbPersonal,2,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 {
}
});
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(cbPersonal,2,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);
textOutputArea.setText("");
for(Account a : accountArray) {
textOutputArea.appendText(" "+a.getCustomer().getName() + " " + 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.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++;
}
}
textOutputArea.appendText(" The total balance of all accounts in the bank is: " + totalBalance + " ");
textOutputArea.appendText(" The average account balance is $" + averageAcctBalance + " of all accounts. ");
textOutputArea.appendText(" The total balance of all Checking accounts in the bank is: $" + totalCheckingBalance + " ");
textOutputArea.appendText(" The total balance of all Gold accounts in the bank is: $" + totalGoldBalance + " ");
textOutputArea.appendText(" The total balance of all Regular accounts in the bank is: $" + totalRegularBalance + " ");
textOutputArea.appendText(" There is a total of: " + checkingAcctCounter + " checking account(s), " + goldAcctCounter + " gold account(s), and " + regularAcctCounter + " regular account(s) in the bank. ");
textOutputArea.appendText(" There are a total of " + emptyAcctCounter + " empty accounts in the bank. ");
textOutputArea.appendText(" The 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: " + 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);
lblNotification.setText("Your ID is: " + newCommercial.getCustomerID());
showPopUp();
});
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, newDate, customer);
accountArray.add(chkAcct);
centerPane.getChildren().clear();
mainPane.setCenter(centerPane);
lblNotification.setText("Checking account has been successfully created. Your accountNumber is: " + chkAcct.getAccountNumber());
showPopUp();
//System.out.println("Checking account has been successfully created. Your accountNumber is: " + chkAcct.getAccountNumber() + " ");
}else{
centerPane.getChildren().clear();
mainPane.setCenter(centerPane);
lblNotification.setText("Customer could not be found");
showPopUp();
}
//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.getText();
boolean customerSelected = false;
Customer customer = null;
for(Customer c : customerArray) {
if(c.getName().equals(customerInput)) {
customer = c;
customerSelected = true;
}
}
if(customerSelected){
Account goldAcct = new GoldAccount(UniqueIDFactory.generateUniqueID(),startingBalance, newDate,customer);
accountArray.add(goldAcct);
centerPane.getChildren().clear();
mainPane.setCenter(centerPane);
lblNotification.setText("Gold account has been successfully created. Your accountNumber is: " + goldAcct.getAccountNumber());
showPopUp();
}else{
centerPane.getChildren().clear();
mainPane.setCenter(centerPane);
lblNotification.setText("Customer could not be found");
showPopUp();
}
//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.getText();
boolean customerSelected = false;
Customer customer = null;
for(Customer c : customerArray) {
if(c.getName().equals(customerInput)) {
customer = c;
customerSelected = true;
}
}
if(customerSelected){
Account regularAcct = new RegularAccount(UniqueIDFactory.generateUniqueID(), startingBalance, newDate,customer);
accountArray.add(regularAcct);
centerPane.getChildren().clear();
mainPane.setCenter(centerPane);
lblNotification.setText("Regular Account has been successfully created. Your accountNumber is: " + regularAcct.getAccountNumber());
showPopUp();
}else{
centerPane.getChildren().clear();
mainPane.setCenter(centerPane);
lblNotification.setText("Customer could not be found");
showPopUp();
}
//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.makeDeposit(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.makeWithdrawal(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 Account Number Account Balance " );
for(Account a : accountArray) {
if(a.getAccountNumber() == accountNumberInput) {
textMainOutputArea.appendText(a.getCustomer().getName() + " " + a.getAccountNumber() + " " + a.getBalance());
}
}
});
btnRemove.setOnAction(actionEvent -> {
long accountNumber;
long accountNumberInput = Long.parseLong(txtAccountNumber.getText());
for(int i = 0; i <= accountArray.size(); i++) {
accountNumber = accountArray.get(i).getAccountNumber();
if(accountNumber == accountNumberInput) {
accountArray.remove(i);
((ArrayList<Account>) accountArray).trimToSize();
System.out.println("Account " + accountNumberInput + " has been removed.");
}
}
});
btnApplyEOM.setOnAction(actionEvent -> {
for(Account a: accountArray) {
if (a instanceof CheckingAccount) {
((CheckingAccount) a).deducteFee(0);
} else if (a instanceof GoldAccount) {
((GoldAccount) a).calculateIntrest();
} else if (a instanceof RegularAccount) {
((RegularAccount) a).calculateIntrest();
}
}
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;
}
@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<Account>) 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 {
@SuppressWarnings("resource")
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();
}
}
}
PersonalCustomer.java : ---------->>>>>>>
/*
* PersonalCustomer.java
*
* A specialized customer representing a personal
* customer
*
* @author AMA
* @since 3/11/2014
* @version 1.0
*/
public class PersonalCustomer extends Customer{
// PersonalCustomer will have the following attributes
// Declaring these private secures the attributes
private String homePhone, workPhone;
/**
*
* Personl customer constructor requiring six
* attributes to create
*
* @param l String the customer name
* @param address String the customer address
* @param phone String the customer phone
* @param homePhone String the customer home phone
* @param workPhone String the customer work phone
*/
public PersonalCustomer(long l, String name, String email,
String homePhone, String workPhone){
// Call superclass constructor
super(""+l,name,"","",email);
this.homePhone = homePhone;
this.workPhone = workPhone;
}
public String getHomePhone(){
return homePhone;
}
public void setHomePhone(String homePhone){
this.homePhone = homePhone;
}
public String getWorkPhone(){
return workPhone;
}
public void setWorkPhone(String workPhone){
this.workPhone = workPhone;
}
/**
*
* String representation of this object
*
* @returns String attributes represented as a String
*/
@Override
public String toString() {
return super.toString() +
" Home Phone: " + homePhone +
" Work Phone: " + workPhone;
}
}
CommercialCustomer.java : ----------->>>>>>>>>>
public class CommercialCustomer extends Customer{
// CommercialCustomer will have the following attributes
// Declaring these private secures the attributes
private int creditRating;
private String contactPerson, contactPersonPhone;
/**
*
* Commercial customer constructor requiring seven attributes to create
*
* @param l String the customer name
* @param address String the customer address
* @param address String the customer phone
* @param creditRating int the customer credit rating
* @param contactPerson String the account contact person
* @param contactPersonPhone String the account contact person phone
*/
public CommercialCustomer(long l, String fullName, String email,
int creditRating, String contactPerson, String contactPersonPhone){
// Call superclass constructor
super(""+l,fullName,"","",email);
this.creditRating = creditRating;
this.contactPerson = contactPerson;
this.contactPersonPhone = contactPersonPhone;
}
public String getContactPerson(){
return contactPerson;
}
public void setContactPerson(String contactPerson){
this.contactPerson = contactPerson;
}
public String getContactPersonPhone(){
return contactPersonPhone;
}
public void setContactPersonPhone(String contactPersonPhone){
this.contactPersonPhone = contactPersonPhone;
}
public int getCreditRating(){
return creditRating;
}
public void setCreditRating(int creditRating){
this.creditRating = creditRating;
}
/**
*
* String representation of this object
*
* @returns String attributes represented as a String
*/
@Override
public String toString() {
return super.toString() +
" Credit Rating: " + creditRating +
" Contact Person: " + contactPerson +
" Contact Person Phone: " + contactPersonPhone;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.