Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In java Ignore the hint on the bottom paragraph. Create an inheritance hierarchy

ID: 3789748 • Letter: I

Question

In java

Ignore the hint on the bottom paragraph.

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 and withdraw (i.e., debit) money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction (i.e., credit or debit). Create an inheritance hierarchy containing base class Account and derived classes Savings-Account and Checking Account that inherit from class Account. Base class Account should include one data member 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 data member. The constructor should validate the initial balance to ensure that it's greater than or equal to 0.0. If not, the balance should be set to 0.0 and the constructor should display an error message, indicating that the initial balance was invalid. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function 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 function should print the message "Debit amount exceeded account balance." Member function get Balance should return the current balance. Derived class SavingsAccount should inherit the functionality of an Account, but also include a data member of type double indicating the interest rate (percentage) assigned to the Account. SavingsAccounts constructor should receive the initial balance, as well as an initial value for the SavingsAccount's interest rate. SavingsAccount should provide a public member function calculatelnterest that returns a double indicating the amount of interest earned by an account. Member function calculatelnterest should determine this amount by multiplying the interest rate by the account balance. SavingsAccount should inherit member functions credit and debit as is without redefining them.] Derived class CheckingAccount should inherit from base class Account and include an additional data member of type double that represents the fee charged per transaction. Checking-Accounts constructor should receive the initial balance, as well as a parameter indicating a fee amount. Class CheckingAccount should redefine member functions credit and debit so that they subtract the fee from the account balance whenever either transaction is performed successfully. CheckingAccount's versions of these functions should invoke the base-class Account version to perform the updates to an account balance. CheckingAccount's debit function should charge a fee only if money is actually withdrawn (i.e., the debit amount does not exceed the account balance). [Define Account's debit function so that it returns a bool indicating whether money was withdrawn. Then use the return value to determine whether a fee should be charged.]

Explanation / Answer

please find the inheritance hierarchy in java

class Account
{
   protected double account_balance;
  
   // parameterised constructor to initialize balance
   Account(double blnc)
   {
       if(blnc<=0.0)
       {
           System.out.println(" Initial balance is invalid");
           this.account_balance=0.0;
       }
       else
           this.account_balance=blnc;
   }

   //function to assign current balance to the account
   public void assign(double bl)
   {
       this.account_balance=bl;
   }

   //function to add an amount to the current balance
   public boolean credit(double amount)
   {
       if(amount<=0.0)
       {
           System.out.println(" Transaction unsucessful!!Please enter a valid amount.");
           return false;
       }
       account_balance+=amount;
       System.out.println(" Transaction completed succcessfully...");
       return true;
   }

   //function to withdraw money from the Account
   public boolean debit(double amount)
   {
       if(amount<=0.0)
       {
           System.out.println(" Transaction unsucessful!!Please enter a valid amount.");
           return false;
       }
       if(amount>account_balance)
       {
           System.out.println(" Transaction unsucessful!!Debit amount exceeded account balance...");
           return false;
       }
       account_balance-=amount;
       System.out.println(" Transaction completed succcessfully...");
       return true;
   }

   //function to return the current balance
   public double getBalance()
   {
       return account_balance;
   }
  
}

//Derived class named SavingsAccount is created which is derived from base class Account
class SavingsAccount extends Account
{

   protected double interest_rate;

   //Parameterized constructor to initialize interest rate and receive initial balance
   SavingsAccount(double balance,double percentage)
   {
       super(balance);
   account_balance=balance;
   interest_rate=percentage;
   }

   //function to return the amount of interest earned by an account
   public double CalculateInterest()
   {
       return account_balance*(interest_rate/100);
   }
}
  
//Derived class named CheckingAccount is created which is derived from base class Account
class CheckingAccount extends Account
{
   protected double fee;
  
   //Parameterized constructor to initialize fee charged per transaction and receive initial balance
   CheckingAccount(double balance,double fee_amount)
   {
   super(balance);
   account_balance=balance;
   fee=fee_amount;
   }
   //This function should charge a fee only if money is actually added
   public boolean credit(double amount)
   {
       if((amount-fee)>=0.0)
       {
           amount-=fee;
           System.out.println("Fee charged succcessfully...");
           return true;
       }
       else
           amount=-99;
       return false;
   }

   //This function should charge a fee only if money is actually withdrawn
   public boolean debit(double amount)
   {
       if((amount-fee)>=0.0)
       {
           amount-=fee;
           System.out.println("Fee charged succcessfully...");
           return true;
       }
       else
           amount=-99;
       return false;
   }
}  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote