File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with a method I'm trying to write

 
Stephen Adams
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am working on a mini project for this course I am doing and I am trying to get a method to work and I am just trying to see if I am on the right track.
OK, I have one class that needs to check a value returned by another method from a second class.
My first method goes something like this:
public double checkOverdraft(){
savingAccount.getBalance();
if (saving.balance >= moneyOut)
allowOverdrawn = true;
else
allowOverdrawn = false;
}
My second class is called savingAccount and it has a method called getBalance, which returns the balance of the saving account, this needs to be checked against to see if then amount that the user whats to go overdrawn by is not more than is in their saving account.
The method getBalance() is ike this:
public double getBalance(){
return balance;
}
NOw my question is, does this sound as though it will work, and how do I call the returned value in the getBalance method in the checkOverdraft method, I am using saving.balance, will this work or is there a better way to call a value returned in another class.
Thanks
Stephen
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stephen,
Welcome to JavaRanch. You are definitely on the right track, but need to make a couple of changes.
First, the signature for checkOverdraft() should be something like public boolean checkOverdraft(savingAccount account, double moneyOut) Then you can finish it out like this:
 
Stephen Adams
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael,
So that I am clear, in my signature for checkOverdraft() I am passing a reference of my second class, then I can use the method (or any method created in that class) in there and then check the returned value from this method in my checkOverdraft() method.
Is that right??
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that right??
Yep.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic