I don't know what I'm doing wrong, I've at it with trial and error for quite some time and still can't figure this one out. Here's the question and I'll add what I have so far at the bottom. Basically I have no idea how to meet these specifications with what I have from my book. Thanks in advance.
Question :
1. Define a Bank Class to hold Account Objects
a) Has a data structure and attributes to manage the Accounts
on the Heap.
b) A Constructor which creates a Bank of any size at runtime.
c) Methods to open(add) account object, close(remove) account object,
show "Account Summary", make a deposit & make a withdrawal
wrapper methods, and other helper methods that would be appropriate.
2. Write a test program to create a Bank object at runtime, add Account
objects, verify your Methods, and remove objects,
Code :
public class Account extends Bank
{
int num;
public Account(int a)
{
super(a);
}
public static void createAccount(Bank c[], int a)
{
c[a] = balance;
}
public double getBalance()
{
return(balance);
}
public int getNum()
{
return num;
}
}
public class Bank
{
static Bank[] b1;
public static Bank balance;
public Bank(int a)
{
b1 = new Bank[a];
}
public void create(int a)
{
double b = ((Object) b1[a]).createAccount(b1,5);
}
public String toString(int a)
{
return("Balance for account #" +b1[a]);
}
}
import java.util.ArrayList;
public class ProgramTester
{
public static void main(String[] args)
{
//ArrayList<Account> accounts = new ArrayList<Account>();
//accounts.add(new Account(5));
Account a1 = new Account(5);
System.out.println(a1.toString());
//Account a1 = accounts.get(1);
//System.out.println(a1.toString());
}
}