Implement an inheritance hierarchy based on the following specifications for

Thehonest
 (Not rated)
 (Not rated)
Chat

 

Step 1: InheritanceTest

Implement an inheritance hierarchy based on the following specifications for Account class, Checking Account class, and Savings Account class:

Account class

 Attributes:   

String Account Name  

Integer Account ID  

Double balance  

Methods:  

constructor:  initialize balance to zero

processDeposit ( ) – accepts a single double parameter containing the deposit amount. Updates the balance by adding the deposit amount to the balance.  

processWithdrawal ( ) – accepts a single double parameter containing the withdrawal amount. Updates the balance by subtracting the withdrawal amount for the balance. Note: For now do not worry about negative balances.  

sets and gets for name, account ID

getBalance to return the balance

displayAccount - this method prints all account information, here is an example:

                        Account:      2345
                        Name:          John Smith
                        Balance:      $120.75

 Attributes:   

String Account Name  

Integer Account ID  

Double balance  

TEST and make sure all methods of the Account class work before continuing!

The CheckingAcct class is a derived class of the Account class. 

It has no additional attributes

Overdraft withdrawls are allowed but the user is charged a $10 overdraft fee

No interest is earned

 Methods:

processWithdrawl() - needs to be overridden so that if the withdrawl causes insufficient funds, subtract $10 overdraft fee and display a message "overdraft fee charged".

displayAccount - this method prints all account information, here is an example:

                        Account type:  Checking
                        Account:      2345
                        Name:          John Smith
                        Balance:      $120.75

The SavingsAcct class  is a derived class of the Account class. 

Overdraft withdrawls are not allowed

Interest is earned

No additional attributes

Methods: 

processWithdrawl() - needs to be overridden so that if the withdrawl causes insufficient funds, a message "insufficient funds" is displayed an no withdrawl is made.

calcInterest ( ) – If the account balance is greater than or equal to 5000.00 an interest rate of 4% or .04 is applied to increase the balance. If the balance is greater than or equal to 3000.00 an interest rate of 3% or .03 is applied to increase the balance. Otherwise use an interest rate of 2%. Return the interest amount.  This method should be called by displayAccount to show interest earned and add it to the balance.

displayAccount - this method prints all account information, here is an example:

                        Account type:                         Savings
                        Account:                     2345
                        Name:                         John Smith
                                    Interest earned:           $5.02
                        Balance:                      $250.75

 Main: 

To demonstrate polymorphism, create an arrayList of Account type that can handle Checking and Savings accounts (thiis is the Bank).  Prompt for name, account number (or assign account number in main) and add at least one checking object and one savings object to the bank array. 
Now use a loop to process all accounts USING THE Bank array:

Make an initial deposit in each account (prompt for amount to deposit)

Display the balance (to verify)

Make a withdrawl with sufficient funds (prompt for amount to withdraw)

Display the balance (to verify)

Make a withdrawl with insufficient funds (prompt for amount to withdraw)

Display the final account information using displayAccount

See example output below:

Creating a checking account, enter name: John Smith
Your checking account number is 1000
Creating a savings account, enter name: Sue Johnson
Your savings account number is 1001
Processing account: 1000
Amount to deposit: 50
Balance is 50.00
Amount to withdraw: 25
Balance is 25.00
Amount to withdraw: 30
$10 Overdraft fee charged!
Balance is -15.00
Account type: Checking
Account: 1000
Name: John Smith
Balance: $-15.00
Processing account: 1001
Amount to deposit: 500
Balance is 500.00
Amount to withdraw: 150
Balance is 350.00
Amount to withdraw: 500
Insufficient funds!
Balance is 350.00
Account type: Savings
Account: 1001
Name: Sue Johnson
Interest earned: $7.00
Balance: $357.00

 

 

 

    • 10 years ago
    A+ Work
    NOT RATED

    Purchase the answer to view it

    • 7z8uhel2.zip