Suppose you are opening your own tiny bank, and want to manage the bank accounts in your bank. In your bank, there are only two kinds of account: checking and saving. Both of them should have an account number, and should be able to perform deposit, withdraw and check balance operations. People can open a new account with some money deposited, or no money at all. Checking account and saving account perform differently in some aspects, and there are some requirement to meet about the bank accounts:
I here provide some simple test code. I should be able directly run this code directly with any additional class you write.
class AccountTest{
public static void main(String[] args){
BankAccount[] bank = new BankAccount[10];
for(int i=0;i<5;i++)
bank[i]=new CheckingAccount(50);
for(int i=5;i<10;i++)
bank[i]=new SavingAccount(100);
for(int i=0;i<10;i++){
bank[i].withdraw(20);
bank[i].deposit(10);
//bank[i].withdraw(10);
}
for(int i=0;i<10;i++){
bank[i].endMonth();
bank[i].print();
}
}
}
From the above code, you should be able to tell all the class name, and maybe their relationship already. Also you can see what are the necessary methods you have to implement. You can add your own to make your own little bank more complete. Also, the test code doesn't cover every requirement I listed above. So, please don't use it as a fully judgment. You'd better write some test code yourself to fully test your implementation.
One more thing requirement is: the bank ONLY allows checking or saving account! ( This means ...... If you can't get it, email me. :-) )
The output should look similar to the following with the basic information about account type, number, and balance. But you can make it as fancy as you like.
>java AccountTest
my checking number is 1, my balance is 38.0
my checking number is 2, my balance is 38.0
my checking number is 3, my balance is 38.0
my checking number is 4, my balance is 38.0
my checking number is 5, my balance is 38.0
my saving number is 6, my balance is 94.5
my saving number is 7, my balance is 94.5
my saving number is 8, my balance is 94.5
my saving number is 9, my balance is 94.5
my saving number is 10, my balance is 94.5
Use some static field to remember the total account number been opened so far.
กก
You only need to submit your .java source code and README if you have one. If you put all your comments inside .java file, it's also fine to only submit the .java files. No .class files please.
กก