Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-17-2010, 01:19 PM   PM User | #1
Da1dmoney
New to the CF scene

 
Join Date: Nov 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Da1dmoney is an unknown quantity at this point
Passing method returned values between class

Is there a way to pass the value of a specific method from one class to another? For instance if i wanted to take the results of this:
Code:
 void withdraw(double amt){
balance = balance - amt;
 if (balance < 0) { 
sendWarning();
applyOverdraftFee();
}
}
And use it in another class like this:
Code:
 public String errorDescription(double balance, BankAccount toAccount)
	  {
 BankAccount method = new BankAccount(balance, acctNumber, acctNumber, acctNumber);
		this.toAccount = toAccount;
if(method.balance >0){ 				
return "ERR2556B - insufficient funds"; 			} 			
else 
return "ERR2312A - not authorized to make this transfer amount";
Basically I am trying to take what ever value is returned from the withdraw method and use it in my other method which is located in another class. If the withdraw method returns a value less then 0, the errorDescription will take that value and print ERR2556B - insufficient funds.
The second class can not be extended if that is an option since its already being extended from another class.
Da1dmoney is offline   Reply With Quote
Old 11-17-2010, 03:56 PM   PM User | #2
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
Set up a get property in the class that has the withdraw method to return the balance and pass that into the class that has the error description method.

I don't do Java but the logic should be straight forward:
PHP Code:
// not sure if Java has properties like c#, back in the day when I used Java it was getter/setter methods
public double getBalance()
{
    return 
this.balance;
}

// pass that into your class that has error description 
Good luck;
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 11-17-2010, 04:32 PM   PM User | #3
Da1dmoney
New to the CF scene

 
Join Date: Nov 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Da1dmoney is an unknown quantity at this point
Thank you i figured out what the problem was using another way. Thank you for your help though!
Da1dmoney is offline   Reply With Quote
Old 11-17-2010, 04:34 PM   PM User | #4
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
Cool, what did you do?
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 11-17-2010, 04:40 PM   PM User | #5
Da1dmoney
New to the CF scene

 
Join Date: Nov 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Da1dmoney is an unknown quantity at this point
I called a get method from its parent class that has the same values returned.
Now all i have to do is remember how to convert my array implementation to ArrayList
Da1dmoney is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:32 AM.


Advertisement
Log in to turn off these ads.