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
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