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 7637697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:00:24+00:00 2026-05-31T08:00:24+00:00

How do I modify computeBalance() making sure that the amounts enetered in the JTextField

  • 0

How do I modify computeBalance() making sure that the amounts enetered in the JTextField is positive ( which I think I did) and is without cents? Example: 100.19 and -49.8 is not acceptable.

public class ATMbizlogic {

    private double totalBalance;
    private boolean rightPinEntered;



    /**
     * Creates a new instance of ATMbizlogic
     */
    public ATMbizlogic() 
    {
        totalBalance = 0.0;
        rightPinEntered =  true;
    }

    public void computeBalance(double withdraw, double deposit)
    throws ATMexception 
    {
        if(withdraw <=0)
            throw new ATMexception("Negative withdraw not allowed");


        if(deposit <=0)
            throw new ATMexception("Negative deposit not allowed");


         double balance = deposit - withdraw;

        totalBalance = totalBalance + balance;



    }



    public void checkPin(double pin)
    throws ATMexception 
    {
        if(pin <=0)
            throw new ATMexception("Negative pin not allowed");
        if(rightPinEntered == false)
            throw new ATMexception("Can not take another pin");
        if(pin<1111 || pin>9999)
            throw new ATMexception("Enter a valid pin");
        rightPinEntered = true;


    }




    public double getBalance()
    {
        return totalBalance;
    }
}
  • 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-31T08:00:25+00:00Added an answer on May 31, 2026 at 8:00 am
    if(floor(withdraw) != withdraw)
        throw new ATMexception("Withdraw with cents is not allowed.");
    
    if(floor(deposit) != deposit)
        throw new ATMexception("Deposit with cents is not allowed.");
    

    That rounds the numbers down and checks if they are still the same number. If it isn’t that means it had a decimal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I modify the structure of a default page category.aspx from Sharepoint Blog template making
How can I modify a SharePoint site so that versioning is turned on by
Is it possible to modify/write data to an XML file without any server-side proxy(e.g.
Possible Duplicate: Modify the URL without reloading the page I know the subject is
I'm trying to modify some exports. I understand that this code doesn't work because
I'm attempting to modify an inherited project that has a convoluted process of displaying
I want to modify an existing Perforce label using a script that I can
I need to modify the vertical and horizontal resolutions without changing the image dimensions.
I'm trying to modify and resize the windows of default.exe which you can find
I am trying to modify the content in my page without a reload. Currently

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.