Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a java program Task 1: Create an inheritance hierarchy that a bank might use to represent customers' bank accounts. All customers at this bank

Create a java program

Task 1: Create an inheritance hierarchy that a bank might use to represent customers' bank accounts.

All customers at this bank can deposit (i.e., credit) money into their accounts.

All customers at this bank can withdraw (i.e., debit)money from their accounts.

More specific types of accounts also exist.

o Savings accounts: Earn interest on the money they hold.

o Checking accounts: Charge a fee per transaction.

Account Class

Create class Account that should include one private instance variable of type double to represent the account balance.

The class should provide a constructor that receives an initial balance and uses it to initialize the instance variable with a public property.

The property should validate the initial balance to ensure that its greater than or equal to 0.0; if not, display an error message (Explore System.err.println).

The class should provide two public methods. o Method Credit should add an amount to the current balance.

o Method Debit should withdraw money from the Account and ensure that the debit amount does not exceed the Accounts balance. If it does, the balance should be left unchanged, and the method should display the message "Debit amount exceeded account balance."

The class should also provide a get accessor in property Balance that returns the current balance.

SavingsAccount Class

Class SavingsAccount should inherit the functionality of an Account, but also include a double instance variable indicating the interest rate (percentage) assigned to the Account.

SavingsAccounts constructor should receive the initial balance, as well as an initial value for the interest rate.

SavingsAccount should provide public method CalculateInterest that returns a double indicating the amount of interest earned by an account.

Method CalculateInterest should determine this amount by multiplying the interest rate by the account balance. [Note: SavingsAccount should inherit methods Credit and Debit without redefining them.]

CheckingAccount Class

Class CheckingAccount should inherit from base class Account and include a double instance variable that represents the fee charged per transaction.

CheckingAccounts constructor should receive the initial balance, as well as a parameter indicating a fee amount.

Class CheckingAccount should redefine methods Credit and Debit so that they subtract the fee from the account balance whenever either transaction is performed successfully.

CheckingAccounts versions of these methods should invoke the base-class Account version to perform the updates to an account balance.

CheckingAccounts Debit method should charge a fee only if money is actually withdrawn (i.e., the debit amount does not exceed the account balance).

After defining the classes in this hierarchy, write an app that creates objects of each class and tests their methods. Add interest to the SavingsAccount object by first invoking its CalculateInterest method, then passing the returned interest amount to the objects Credit method. The tester class should be a different class.

Task 2: Lets update the Task1 and create an array of Account references to SavingsAccount and CheckingAccount objects. For each Account in the array, allow the user to specify an amount of money to withdraw from the Account using method Debit and an amount of money to deposit into the Account using method Credit. As you process each Account, determine its type. If an Account is a SavingsAccount, calculate the amount of interest owed to the Account using method CalculateInterest, then add the interest to the account balance using method Credit. After processing an Account, display the updated account balance obtained by using baseclass property Balance.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions