I thought some concepts are clear, but apparently that's not exactly true. I'm sure it's something very simple and asking you to answer rather than blame me or mark as duplicate etc, since I searched other similar questions, but they are not exactly as mine.
So I have this simple class Bank that creates an array of objects BankAccount by giving it the size. The Bank class has method isFull to check if the array is full, which, however I cannot call from a class MainApp where I just create instances to test my methods.
Bank
public class Bank {
// array of BANKACCOUNT objects
private BankAccount[] accountList; // will hold all the accounts
private int totalAccounts; // to hold the total number of accounts
public Bank(int sizeIn) {
totalAccounts = sizeIn;
accountList = new BankAccount[totalAccounts];
}
// check if the list is full
public boolean isFull() {
if(accountList.length == totalAccounts) {
return true;
}
return false;
}
// add an item to the array
public boolean add(BankAccount accountIn) {
boolean added = false;
if(isFull()){
System.out.println("The account list is full");
added = false;
} else {
accountList[totalAccounts] = accountIn;
totalAccounts++;
added = true;
}
return added;
}
// other methods...
BankAccount
public class BankAccount {
private String nameOfHolder;
private String accNumber;
private double balance;
private static double interestRate;
public BankAccount(String INPname, double INPbalance){
accNumber = "NL35FAKE" + Randomize.RandomNumGen(); //created a random number for every bank account in a separate class
nameOfHolder = INPname;
balance = INPbalance;
}
// other methods...
Main program
public class MainApp {
Bank[] bankList = new Bank[3];
BankAccount acc1 = new BankAccount("Stacey", 7500);
BankAccount acc2 = new BankAccount("Maria", 15000);
bankList[0].add(acc1);
bankList[1].add(acc2);
bankList.isFull(); // THIS DOES NOT WORK.
I do not see the isFull() method unless if I call it this way:
bankList[0].isFull() which makes no sense as I want to check the link of accounts.
Thanks in advance. :)