Code:
public class Account{
//class Variables
private static int NumAccounts = 0;
private static final double Interest = 0.05;
//Instant Variables
private long accNum;
private double balance;
public Account(long accN, double bal){
accNum = accN;
balance = bal;
NumAccounts++;
}
public int GetNumAccounts(){
return NumAccounts;
}
public double getBalance(){
return balance;
}
public long getAccountNum(){
return accNum;
}
public void debit(double amount){
if(amount > balance){
System.out.println("Insufficient Funds in your Account");
}else{
balance = balance - amount;
}
}
public void credit(double amount){
balance += amount;
}
public String toString(){
String Str;
Str ="Account Number :" + accNum + "\n"+
"Account Balance :" + balance + "\n";
return Str;
}
}//End of class Account
public class TestAccount{
static Account[]accList= new Account[100];
public static void insertIntoArray(Account p){//Insert Objects into account
int u = 1;
accList[u++] = p;
}
public void print(){ // Print objects
System.out.println("Account Number :" + accNum);
System.out.println("Balance :" + balance);
}
public static void main(String[] args){
// Account []accList = new Account[1000];
Account a = new Account(123456,5255.17);
insertIntoArray(a);
Account b = new Account(188468,19218.20);
insertIntoArray(b);
Account c = new Account(217794,1002.62);
insertIntoArray(c);
Account d = new Account(998283,20203.75);
insertIntoArray(d);
for(int i = 1; i <= 4; i++){// print array elements
System.out.println(accList[i].print());
}
}//end main
}//end class TestAccount
I am to assume an array, accList, to hold Accounts objects. TestAccount has a method insertIntoArray(Account). Next, I am to create four account objects, insert them into the array and then print them. When I try to print I am getting the following errors:
Cannot find symbol variable accNum;
Cannot find symbol variable balance;
Cannot find symbol method print();
