Forums Register Login

Getting a return value from a function and using it another fuction

+Pie Number of slices to send: Send
Hello,
I have a simple function that checks a value passed in and returns a value depending on the original value, like this:
public void setBalance(double balance){
if(balance >= 0){
this.balance=balance;
return true;
}
else{
return false;
}
}
Then I want to use the result of this function in another function, that displays a message to the user, e.g.
public void isBalanceNegative(double balance,){
if(){
System.out.println("You cannot enter a negative number");
}
else{
System.out.println("Your current balance is " + balance);
}
}
The two problems I am having are, one how to pass the returned true or false value from the setBalance function to the isBalanceNegative function and how to get the balance to the isBalanceNegative function too.
I suppose the main question is how to pass the results of one function to another?
THanks
Stephen
+Pie Number of slices to send: Send
you must set a return type
[CODE]
public boolean setBalance(double balance){
if(balance >= 0){
this.balance=balance;
return true;
}else{
return false;
}
}
[CODE]
and then call your method like
[CODE]
booelan result = setBalance()
[CODE]
this value you can then easily check.
+Pie Number of slices to send: Send
Cool, thanks Oliver.
Let's go to the waterfront with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 981 times.
Similar Threads
Reflection Mechansim to access private data.
Need help with username and password validation
return Boolean
Program like ATM where person enters amount in dollars and cents but program uses int for monies
super Constructor
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:02:16.