Menu

(Solved) : Lot Bugs Project Program Funcition Right Please Take Look Project Find Bugs Could Please F Q30331392 . . .

I have a lot of bugs in my project, the program is not funcitionright!! can you please take a look to my project and if you findany bugs could you please fix it. i copy all my code here if youcannot upload all the code just reply manytimes untill the all codeis fixed please.

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 implementsSerializable{

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 = newLabel(“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 CheckingAccount”),
btnSubmitGold = new Button(“Create Gold Account”),
btnSubmitPersonalCust = new Button(“Create PersonalCustomer”),
btnSubmitCommercialCust = new Button(“Create CommercialCustomer”),
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, CreateGold Account, Create Regular Account

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

MenuItem checkingMenu = new MenuItem(“Create CheckingAccount”);
createMenu.getItems().add(checkingMenu);

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

MenuItem regularMenu = new MenuItem(“Create RegularAccount”);
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 AccountInfo”);
displayMenu.getItems().add(accountInfoMenuItem);

MenuItem allAccountsMenuItem = new MenuItem(“Display AllAccounts”);
displayMenu.getItems().add(allAccountsMenuItem);

MenuItem bankStatsMenuItem = new MenuItem(“Display BankStats”);
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() + “ttt” +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(“nTotal 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(“tThe total balance of all accounts inthe bank is: ” + totalBalance + “n”);
textOutputArea.appendText(“tThe average account balance is $” +averageAcctBalance + ” of all accounts.n”);
textOutputArea.appendText(“tThe total balance of all Checkingaccounts in the bank is: $” + totalCheckingBalance + “n”);
textOutputArea.appendText(“tThe total balance of all Gold accountsin the bank is: $” + totalGoldBalance + “n”);
textOutputArea.appendText(“tThe total balance of all Regularaccounts in the bank is: $” + totalRegularBalance + “n”);
textOutputArea.appendText(“tThere is a total of: ” +checkingAcctCounter + ” checking account(s), ” + goldAcctCounter +” gold account(s),ntt and ” + regularAcctCounter + ” regularaccount(s) in the bank.n”);
textOutputArea.appendText(“tThere are a total of ” +emptyAcctCounter + ” empty accounts in the bank.n”);
textOutputArea.appendText(“tThe customer with the largest balanceis: ” + largestAccount + “n”);
}

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

btnSubmitPersonalCust.setOnAction(actionEvent -> {

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

Customer newPersonal = newPersonalCustomer(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 = newCommercialCustomer(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 = newCheckingAccount(UniqueIDFactory.generateUniqueID(),startingBalance,customer, newDate);
accountArray.add(chkAcct);
System.out.println(“Checking account has been successfully created.Your accountNumber is: ” + chkAcct.getAccountNumber() +”n”);
}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 = newGoldAccount(UniqueIDFactory.generateUniqueID(),startingBalance,customer, newDate);
accountArray.add(goldAcct);
System.out.println(“Gold account has been successfully created.Your accountNumber is: ” + goldAcct.getAccountNumber() + “n”);

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 = newRegularAccount(UniqueIDFactory.generateUniqueID(), startingBalance,customer, newDate);
accountArray.add(regularAcct);
System.out.println(“Regular Account has been created. Your accountnumber is : ” + regularAcct.getAccountNumber() + “n”);

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 NamettAccountNumberttAccount Balancen” );

for(Account a : accountArray) {
if(a.getAccountNumber() == accountNumberInput) {
textMainOutputArea.appendText(a.getCustomer().getName() +”ttttt” + a.getAccountNumber() + “ttt” +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) accountArray).trimToSize();
System.out.println(“Account ” + accountNumberInput + ” has beenremoved.”);

}
}

});

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 {
ObjectInputStream input = new ObjectInputStream(newFileInputStream(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(newFileOutputStream(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 numberfor the customer

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

protected Calendar dateOpened; // used to show the dateopened

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

  

/**

*

* 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, CalendardateOpened, 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 themin 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/ddHH:mm:ss”);

output += “nAccount Number: ” + this.accountNumber;

output += “nAccount Balance: ” + this.balance;

output += “nAccount Date open: ” +dateFormat.format(dateOpened.getTime());

output += “nCustomer Account: ” + this.customer;

return output;

}

}

_______________________

import java.util.ArrayList;

import java.util.Calendar;

import java.util.Scanner;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.ObjectOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

//import com.bank.account.Account;

//import com.bank.account.CheckingAccount;

public class Bank {

// arrayList to store the information for the bank system

static ArrayList accounts = new ArrayList();

@SuppressWarnings(“unchecked”)

public static void main(String[] args) {

// creating a file for the project and make the arrayList savethe information in this file

File file = new File (“AccountData.ser”);

if (file.exists()){

try{

@SuppressWarnings(“resource”)

ObjectInputStream in = new ObjectInputStream(newFileInputStream(file));

accounts = (ArrayList)in.readObject();

}

catch (IOException ioException){

ioException.printStackTrace();

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

// we use Scanner to make the user enter his information

@SuppressWarnings(“resource”)

Scanner input = new Scanner(System.in);

// Start the menu to make the user chose from it

boolean keepLooking = true;

while(keepLooking){

int choice;

{

System.out.println(“”);

System.out.println(” Bank Menu”);

System.out.println(” =====================”);

System.out.println(” 1. Create Checking Account”);

System.out.println(” 2. Create Gold Account”);

System.out.println(” 3. Create Regular Account”);

System.out.println(” 4. Deposit”);

System.out.println(” 5. Withdrawl”);

System.out.println(” 6. Display Account Info”);

System.out.println(” 7. Remove an Account”);

System.out.println(” 8. Apply end of month “);

System.out.println(” 9. Display Bank Statistics”);

System.out.println(” 10. Exit”);

System.out.println(“Enter your choice (1-10): ” );

choice = input.nextInt();

// we do switch to make each number do something

// or we can use if statement will work too

switch(choice)

{

case 1:

//Creating an account to the customer

String name;

String customerID;

String yourAdress;

String phoneNumber;

long accountNumber;

// creating a CheckingAccount for the customer

// we use the user input here to save the information

System.out.println(“nPlease input the customer name: “);

name = input.next();

System.out.println(“nPlease input Your Address: “);

yourAdress = input.next();

System.out.println(“nPlease input your Phone Number: “);

phoneNumber = input.next();

System.out.println(“nPlease input the customer ID : “);

customerID = input.next();

System.out.println(“nPlease input the account number: “);

accountNumber = input.nextLong();

// Create a Customer in order to Create an account

Customer sam = new Customer(customerID,name,yourAdress,phoneNumber);

//Create an account for the user

Calendar dateOpened = Calendar.getInstance();

Account myCheckingAccount = newCheckingAccount(accountNumber,00.00,dateOpened, sam);

System.out.print(myCheckingAccount);

accounts.add(myCheckingAccount); // adding the checking accountto the ArryList

System.out.println(“nYour Checking Account was createdsuccessfully!”);

keepLooking = true;continue;

case 2:

//create a Gold Account

System.out.print(“nPlease input the customer name: “);

name = input.next();

System.out.print(“nPlease input the customer ID : “);

customerID = input.next();

System.out.print(“nPlease input the account number: “);

accountNumber = input.nextLong();

// Create a Customer in order to Create an account

Customer cal = newCustomer(customerID,name,”Carmel”,”615-713-6049″);

// Create the Gold Account for the Customer

Calendar dateOpened1 = Calendar.getInstance();

Account myGoldAccount = newGoldAccount(accountNumber,1500,dateOpened1, cal);

System.out.print(myGoldAccount);

accounts.add(myGoldAccount);

System.out.print(“nYour Gold Account was createdsuccessfully!”);

keepLooking = true;continue;

case 3:

//create a Regular Account

System.out.print(“nPlease input the customer name: “);

name = input.next();

System.out.print(“nPlease input the customer ID : “);

customerID = input.next();

System.out.print(“nPlease input the account number: “);

accountNumber = input.nextLong();

// Create a Customer in order to Create an account

Customer andrew = newCustomer(customerID,name,”Indiana”,”615-713-6049″);

// Create the Gold Account for the Customer

Calendar dateOpened11 = Calendar.getInstance();

Account myRegularAccount = new RegularAccount(accountNumber,6000,dateOpened11, andrew);

System.out.print(myRegularAccount);

accounts.add(myRegularAccount);

System.out.print(“nYour Regular Account was createdsuccessfully!”);

keepLooking = true;continue;

case 4:

// make the system search for the account in order to let theuser make a deposit

long accNum;

double amount;

System.out.print(“Please input the account number: “);

accNum = input.nextLong();

Account ac = find(accNum);

if(ac == null)

System.out.println(“nAccount number not found!”);

else

{

System.out.print(“Please input the amount: “);

amount = input.nextDouble();

ac.makeDeposit(amount);

System.out.println(“nAccount updated successfully!n”);

}

keepLooking = true;continue;

case 5:

// Making the system search for the account in order to let theuser make a withdraw

System.out.print(“Please input the account number: “);

accNum = input.nextInt();

Account acc = find(accNum);

if(acc == null)

System.out.println(“nAccount number not found!”);

else

{

System.out.print(“Please input the amount: “);

amount = input.nextDouble();

acc.makeWithdrawal(amount);

System.out.println(“nAccount updated successfully!n”);

}

keepLooking = true;continue;

case 6:

// Here the Information for the account well display

System.out.print(“nPlease input the customer ID : “);

customerID = input.next();

System.out.print(“nPlease input the account number: “);

accountNumber = input.nextLong();

for (Account c: accounts){

if(c.getAccountNumber()==accountNumber &&c.getCustomer().getCustomerID().equals(customerID)){

System.out.print(c);

break;

}

}

keepLooking = true;continue;

case 7:

// here we make the user remove the account from the the systemand from the arraylist

Account accountt = null;

//Remove an Account

System.out.println(“Please enter account number: “);

accountNumber = input.nextLong();

for(Account a:accounts){

if(a.getAccountNumber()==accountNumber){

accountt=a;

break;

}

}

accounts.remove(accountt);

System.out.println(“Account successfully removed!”);

keepLooking = true;continue;

case 8:

// here we make the user to apply each month transaction

double principal = 0;

double rate = 0;

double time = 0;

double compoundInterest = 0;

System.out.print(“Enter the Principal amount : “);

principal = input.nextDouble();

System.out.print(“Enter the Rate : “);

rate = input.nextDouble();

System.out.print(“Enter the Time : “);

time = input.nextDouble();

compoundInterest = principal * Math.pow((1 +rate/100),time);

System.out.println(“”);

System.out.println(“The Compound Interest is : “

+ compoundInterest);

keepLooking = true;continue;

case 9:

// display the statistic for the bank system

for (Account s: accounts){

System.out.println(s.toString());

}

keepLooking = true;continue;

case 10:

//Exit from the system

System.exit(10);

break;

// here if the user chose a wrong number

default:

System.out.println(“Invalid Choice”);

}

}

//Store the ArrayList into a file named EmployeeData.ser

//Arrays and ArrayLists are objects

try{

@SuppressWarnings(“resource”)

ObjectOutputStream out = new ObjectOutputStream(newFileOutputStream(“AccountData.ser”));

out.writeObject(accounts);

}

catch(IOException ioException){

ioException.printStackTrace();

}

}

}

public static Account find(long accNum)

{

for (Account a : accounts)

{

if (a.getAccountNumber() == accNum) // Found a match

return a;

}

return null; // No match in the entire ArrayList

}

}

______________________

/*

* 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 twomonth.

// 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;

}

}

___________________

/*
* CommercialCustomer.java
*
* A specialized customer representing a commercial customer
*
* @author AMA
* @since 3/11/2014
* @version 1.0
*/

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 tocreate
*
* @param l String the customer name
* @param address String the customer address
* @param address String the customer address
* @param creditRating int the customer credit rating
* @param contactPerson String the account contact person
* @param contactPersonPhone String the account contact personphone
*/
public CommercialCustomer(long l, String address, Stringphone,
int creditRating, String contactPerson, StringcontactPersonPhone){
// Call superclass constructor
super();
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() +
“nCredit Rating: ” + creditRating +
“nContact Person: ” + contactPerson +
“nContact Person Phone: ” + contactPersonPhone;
}
}

_______________________

/*

* 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;

public Customer(){

this.customerID = “”;

this.name = “”;

this.address = “”;

this.phoneNumber = “”;

}

public Customer (String customerID,String name,Stringaddress,String phoneNumber){

this.customerID = customerID;

this.name = name;

this.address = address;

this.phoneNumber = phoneNumber;

}

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 += “nCustomer ID: ” + this.customerID;

output += “nCustomer Name: ” + this.name;

output += “nCustomer Address: ” + this.address;

output += “nCustomer Phone Number: ” + this.phoneNumber;

return output;

}

}

_________________________

/*

* 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, CalendardateOpened, 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;

}

}

_______________________

/*
* 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 address, String phone,
String homePhone, String workPhone){
// Call superclass constructor
super();
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() +
“nHome Phone: ” + homePhone +
“nWork Phone: ” + workPhone;
}
}

_______________________

/*

* 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;

}

}

__________________

/*
* UniqueIDFactory.java
*
* Utility class to generate unique ids
*
* @author AMA
* @since 3/10/2014
* @version 1.0
*/

import java.util.Calendar;

public class UniqueIDFactory {

/*
* Returns a unique long number
*
* @returns unique id long
*/
public static long generateUniqueID(){
  
return Calendar.getInstance().getTimeInMillis();
  
}
  
}

Expert Answer


Answer to Lot Bugs Project Program Funcition Right Please Take Look Project Find Bugs Could Please F Q30331392 . . .

OR