this is a homework problem and it is giving me null pointer exception when i run the tester. the error seems to be in my line
balance[i]=InitialBalance;
public class Bank
{
private BankAccount[] accounts;
private double [] balance;
int NumbersOfBankAccount;
double InitialBalance;
public Bank (int x, double y )
{
NumbersOfBankAccount = x;
InitialBalance = y;
}
/**
* This method will get balance of specified bank account.
*/
public double getBalance(int index)
{
for(int i = 0; i <NumbersOfBankAccount; i++)
{
balance[i]=InitialBalance;
}
System.out.println(balance);
return balance[index];
}
}
getBalance
will always returnInitialBalance
(provided thatindex
is within array range). – jlordo Nov 5 '12 at 22:13