File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Help with a method I'm trying to write Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with a method I Watch "Help with a method I New topic
Author

Help with a method I'm trying to write

Stephen Adams
Greenhorn

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

Joined: Jan 30, 2002
Posts: 3451
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:


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Stephen Adams
Greenhorn

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

Joined: Jan 30, 2002
Posts: 3451
Is that right??
Yep.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help with a method I'm trying to write
 
Similar Threads
printf problems
Having trouble understanding an error code i keep getting. Please help!
Program like ATM where person enters amount in dollars and cents but program uses int for monies
return Boolean
Constructor issues with creating a new checking account object.