I am working on modifying a BankAccount class for a project I'm doing. I am almost finished, but I am stuck on my second constructor. If a user has an existing account (i.e if there is an initial balance), then the BankAccount constructor should call a deposit method to allow the user to add some money if he or she wants to. However, the parameter which passes the value to the deposit method is not available for this constructor and I know that I can not simply add that parameter to the BankAccount constructor. Right now, I have decided to use a separate variable for that constructor exclusively, but I am afraid it my break my partner's code. What would be a better way to go about this?
/*
The variable I am using for the called deposit method in
this constructor.
*/
private double amount;
/**
Constructs a bank account with a given balance
@param anAccountNumber the account number for this account
@param initialBalance the initial balance
*/
public BankAccount(int anAccountNumber, double initialBalance)
{
status= OPEN_ACCOUNT;
transactions= new ArrayList<Double>();
accountNumber = anAccountNumber;
balance = initialBalance;
getStatus();
if(initialBalance >= 0)
{
deposit(amount);
}
}
/**
Deposits money into the bank account.
@param amount the amount to deposit
*/
public void deposit(double amount)
{
isOpen();
if(status.equals(OPEN_ACCOUNT) && amount > 0)
{
double newBalance = balance + amount;
balance = newBalance;
addTransaction(amount);
}
}