Question: Account Class Write an Account class containing instance variables called balance and accountNumber, and static instance variables named totalBalances and nextAccountNumber. nextAccountNumber should be initialized

Account Class Write an Account class containing instance variables called balance and accountNumber, and static instance variables named totalBalances and nextAccountNumber. nextAccountNumber should be initialized to 1. The class should have a no argument constructor that creates an account with a 0 balance and another constructor that creates an account with the given balance. The class should also have mutators called deposit and withdraw, accessors called getBalance, isOverdrawn and a static method named GetTotalAccounts that gives the total sum of all accounts. The class should also have a public constant named OVERDRAFT_FEE equal to 20.00. Whenever an account is created, the constructor should set the account number to be nextAccountNumber and then increment nextAccountNumber by 1. Any time deposit or withdraw methods are called they should update not only the balance instance variable but also the static allBalances instance variable. If after a withdrawal the account balance is below 0, an additional amount equal to OVERDRAFT_FEE should be subtracted. The isOverdrawn method should return true if the balance is below 0 and false otherwise. In testing this program you should create multiple account objects with varying values and display the statuses of the accounts. Dollar values should be properly formatted with 2 decimal places and a dollar sign. All account numbers should display as 6 digit numbers. Example of running Created account 000001 with $150.00 Created account 000002 with $75.00 Withdrawal from account 000001 of $100.00 Account number=000001, balance=$50.00, Not overdrawn Account number=000002, balance=$75.00, Not overdrawn Total of accounts = $125.00 Withdrawal from account 000001 of $75.00 Account number=000001, balance=$-45.00, Overdrawn Account number=000002, balance=$75.00, Not overdrawn Total of accounts = $30.00

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!