Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7074347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:02:41+00:00 2026-05-28T06:02:41+00:00

Ok, so I hope you can all help, I have been tasked whilst tying

  • 0

Ok, so I hope you can all help, I have been tasked whilst tying to learn the language with the age-old test of simple savings account and checking account using inheritence.

My problem is, I want to make the checking account incapable of going over its overdraft limit and the savings account incapable of going below 0 but cant work out how? my code so far is as follows:

SUPERCLASS (BankAccount):

public class BankAccount
    {
        protected String CustomerName;
        protected String AccountNumber;
        protected float Balance;


//Constructor Methods

 public BankAccount(String CustomerNameIn, String AccountNumberIn, float BalanceIn)
        {
            CustomerName = CustomerNameIn;
            AccountNumber = AccountNumberIn;
            Balance = BalanceIn;

        }

      // Get  name
      public String getCustomerName()
        {
            return (CustomerName);
        }

      // Get account number
      public String getAccountNumber()
        {
            return (AccountNumber);
        }

       public float getBalance()
        {
            return (Balance);
        }


        public void Withdraw(float WithdrawAmountIn)
       {  
           if(WithdrawAmountIn < 0)
                System.out.println("Sorry, you can not withdraw a negative amount, if you wish to withdraw money please use the withdraw method");
           else
                Balance = Balance - WithdrawAmountIn;
       }

        public void Deposit(float DepositAmountIn)
       {
           if(DepositAmountIn < 0)
                System.out.println("Sorry, you can not deposit a negative amount, if you wish to withdraw money please use the withdraw method");
           else 
           Balance = Balance + DepositAmountIn;
       }


    } // End Class BankDetails

SUBCLASS (SavingsAccount):

public class SavingsAccount extends BankAccount
  {   

      private float Interest;

      public SavingsAccount(String CustomerNameIn, String AccountNumberIn, float InterestIn, float BalanceIn)
        {
            super (CustomerNameIn, AccountNumberIn, BalanceIn);
            Interest = InterestIn;
        }


      public float getInterestAmount()
       {
           return (Interest);
       }

      public float newBalanceWithInterest()
       {  
           Balance = (getBalance() + (getBalance()  * Interest / 100) );

           return (Balance);
       }

       public void SavingsOverdraft()
       {
            if( Balance < 0)
                System.out.println("Sorry, this account is not permitted to have an overdraft facility");
       }

   }

SUBCLASS (CheckingAccount):

public class CheckingAccount extends BankAccount
  {
      private float Overdraft;


      public CheckingAccount(String CustomerNameIn, String AccountNumberIn, float BalanceIn, float OverdraftIn)
        {

            super (CustomerNameIn, AccountNumberIn, BalanceIn);

            Overdraft = OverdraftIn;
        }

       public float getOverdraftAmount()
       {
           return(Overdraft);
       }

      public void setOverdraft()
        {
            if (Balance < Overdraft)
                System.out.println("Sorry, the overdraft facility on this account cannot exceed £100");

       }
    }

Thank you very very much for any advice and help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:02:42+00:00Added an answer on May 28, 2026 at 6:02 am

    Add getOverdraftAmount() to your base class:

    public int getOverdraftAmount() {
        return 0;
    }
    

    Then override that method in account subclasses that allow overdrafts. Then revise your logic for withdrawal to take into account that the overdraft limit might not be zero.

    public void Withdraw(float WithdrawAmountIn)
       {  
           if(WithdrawAmountIn < 0)
                System.out.println("Sorry, you can not withdraw a negative amount, if you wish to withdraw money please use the withdraw method");
           else if (Balance - WithdrawAmountIn < -getOverdraftAmount()) {
                System.out.println("Sorry, this withdrawal would exceed the overdraft limit");
           else 
                Balance = Balance - WithdrawAmountIn;
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope you can help. This has been confounding me for hours. I have
I hope someone can help... This issue has been discussed here and I have
I have been trying to figure this out for days. Hope someone can help.
hope someone can help. I have two tables: Users -UserID -UserName UsersType -UserTypeID -UserID
I hope you can help me. I have a web service that needs to
I hope somebody can help me. I've been trying to write a custom html
I hope someone can offer any help!! I have web page that initiates a
I am a very new beginner and have been reading the help forums. All
all, I hope you can either help me, or direct me the the easy-to-find-in-retrospect
I hope you can help me here... I have a conflict with the decimal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.