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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:37:30+00:00 2026-06-15T07:37:30+00:00

I just wrote this simple methode that must return a double value. It’s a

  • 0

I just wrote this simple methode that must return a double value. It’s a function to withdraw money from the bank account. The function must let the user get the money only if he entries a value smaller than his the amount of money he has in his account.
There is a condition where, if he is a special user, he can take the money even if he tries a value = balance+1000.

As I’m a beginner to java, I’m not yet familiar with this thing of types (I’m a php programmer, so I never really had to worry about this, but I’m getting troubles to make this code work, because I’m returning a double, if it’s ok, but a false, if it’s not, and I can’t do this in java.. This is my methode.. (the variables ‘balance’ and ‘special’ belongs to my class).

public double getMoney (double value) {
    if (value <= balance) {
        balance = balance - value;
    } else {
        if (special == true && value < (balance+1000)) {
            return balance-value;
        } else {
            return false;
        }
    }
}

I know it’s a noob question, but I just started studying java and I was used to code using PHP, where I don’t need to worry about the type of my variables, so I was wondering if you could give me some advices.
Thanks

  • 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-06-15T07:37:31+00:00Added an answer on June 15, 2026 at 7:37 am

    You could return Double.NEGATIVE_INFINITY, instead of false.
    Then the caller explictly checks for that value, and detects ist as invalid withDrawn().

    The caller checks that by

    double val = getMoney(5000000);
    if (val == Double.NEGATIVE_INFINITY) {
       // money could not be withdran
       // print message
    } else {
       // ok money could be withdrawn
    }
    

    If you want to do that more professional you would have to retun a transactionInfo:

    TransActionInfo info = getMoney(500000);
    if (info.getStatus == Status.LIMIT_EXCEEDED) {
       // could not withraw
    
    } else {
       ...
    }
    

    Instead of the if you could use a switch statement:

    TransActionInfo info = getMoney(500000);
    switch (info.getStatus()) {
      case: Status.OK: 
         break;
      case Status.LIMIT_EXCEEDED:
        // inform on display of bankomat. or similar
         break;
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just for fun, I wrote this simple function to reverse a string in Python:
I was comparing a simple hash function that I wrote which just multiplies it
Let's say I wrote a pretty simple class called ValueFinder that looks like this:
I just wrote some simple sample code to make sure that I had EclEmma
I just wrote this into my WebForms .aspx: <span id=GenerateChartButton runat=server></span> I went to
I'm really confused, I just wrote this x = 0 y = 42 #Can
I wrote a program to solve a complicated problem. This program is just a
I'm just wondering if there is a best case to write this code: $('#set_duration_30').click(function(event)
Just wrote a web service and try to return columns of a sharepoint list
I just wrote a very simple perl tk script to read a huge text

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.