Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a project in java but it need to fix the bugs please: here where i found the bug: the first problem is in

I have a project in java but it need to fix the bugs please:

here where i found the bug:

the first problem is in Case 1 : I tried to make the user input his address and his phone number to save it in the recorde!! But it gave me the 3 steps together and it not saving the information for the address and the phone number!!

That's also applay for case 2,and 3.

The second problem: In case 6 display the account information: I need it a way that ask the user put the account number and put the idNumber in order to show him the details of the account!!

The thirde problem: on Case 7 when you try to remove an account it gave you you did that succusfly but it acctullay not deleting the account!!

The fourth problem: case 9 it give me a bug when you hit 9 is not showing the statistic for the bank!!

Here is the code:

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 save the information in this file

File file = new File ("AccountData.ser");

if (file.exists()){

try{

@SuppressWarnings("resource")

ObjectInputStream in = new ObjectInputStream(new FileInputStream(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(" Please input the customer name: ");

name = input.next();

System.out.println(" Please input Your Address: ");

yourAdress = input.next();

System.out.println(" Please input your Phone Number: ");

phoneNumber = input.next();

System.out.println(" Please input the customer ID : ");

customerID = input.next();

System.out.println(" Please 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 = new CheckingAccount(accountNumber,00.00,dateOpened, sam);

System.out.print(myCheckingAccount);

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

System.out.println(" Your Checking Account was created successfully!");

keepLooking = true;continue;

case 2:

//create a Gold Account

System.out.print(" Please input the customer name: ");

name = input.next();

System.out.print(" Please input the customer ID : ");

customerID = input.next();

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

accountNumber = input.nextLong();

// Create a Customer in order to Create an account

Customer cal = new Customer(customerID,name,"Carmel","615-713-6049");

// Create the Gold Account for the Customer

Calendar dateOpened1 = Calendar.getInstance();

Account myGoldAccount = new GoldAccount(accountNumber,1500,dateOpened1, cal);

System.out.print(myGoldAccount);

accounts.add(myGoldAccount);

System.out.print(" Your Gold Account was created successfully!");

keepLooking = true;continue;

case 3:

//create a Regular Account

System.out.print(" Please input the customer name: ");

name = input.next();

System.out.print(" Please input the customer ID : ");

customerID = input.next();

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

accountNumber = input.nextLong();

// Create a Customer in order to Create an account

Customer andrew = new Customer(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(" Your Regular Account was created successfully!");

keepLooking = true;continue;

case 4:

// make the system search for the account in order to let the user 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(" Account number not found!");

else

{

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

amount = input.nextDouble();

ac.makeDeposit(amount);

System.out.println(" Account updated successfully! ");

}

keepLooking = true;continue;

case 5:

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

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

accNum = input.nextInt();

Account acc = find(accNum);

if(acc == null)

System.out.println(" Account number not found!");

else

{

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

amount = input.nextDouble();

acc.makeWithdrawal(amount);

System.out.println(" Account updated successfully! ");

}

keepLooking = true;continue;

case 6:

// Here the Information for the account well display

for (Account c: accounts){

System.out.print(c);

}

keepLooking = true;continue;

case 7:

// here we make the user remove the account from the the system and from the arraylist

Account accountt = null;

//Remove an Account

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

accountNumber = input.nextLong();

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

accounts.add(s);

}

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(new FileOutputStream("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 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;

}

}

_____________

/*

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

}

}

_____________

/*

* 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,String address,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 += " Customer ID: " + this.customerID;

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

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

output += " Customer 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, 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;

}

}

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

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

Prove: log a (x/y) = log a x - log a y.

Answered: 1 week ago

Question

Explain budgetary Control

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago

Question

What are the different techniques used in decision making?

Answered: 1 week ago