aspose file tools*
The moose likes Java in General and the fly likes Getting a return value from a function and using it another fuction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Getting a return value from a function and using it another fuction" Watch "Getting a return value from a function and using it another fuction" New topic
Author

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

Stephen Adams
Greenhorn

Joined: Mar 18, 2002
Posts: 22
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
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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.
Stephen Adams
Greenhorn

Joined: Mar 18, 2002
Posts: 22
Cool, thanks Oliver.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting a return value from a function and using it another fuction