• 0

Java get method returning 0...


Question

Right so i created these classes a while ago and now i was asked to implement a gui interface.

This is when i discovered that my original code wasn't so great.. LOL

So basically my problem is, i am unable to get the endingBalance into the label on the panel..

using getEndBalance() i get a return value of 0.0 So basically it gives me the un initialized value instead of the value that goes to toString..

(same goes for the rest of the "get" methods..)

If anyone could help me on this i would really appreciate it.

Code:

http://www.nopaste.nl/?paste=1370 - AccountInformation

http://www.nopaste.nl/?paste=1371 - AccountPanel

http://www.nopaste.nl/?p=redirect&id=1372 - RetirementCalculator

Ive been stumped for a bit on this one,

Thanks again.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

What does

System.out.println("Debugging endBalance:"+ getEndBalance());

return?

I guess nothing but still...

Edit: You're calling methods without having a receiver.

If you want to getEndBalance() then you'll have to tell the VM from which object. Just add values in front of the method. You'll have to loop over the array to get the values of each element of the array if that's what you want to achieve.

By the way, Vectors are much more elegant when dealing with arrays of objects:

http://java.sun.com/javase/6/docs/api/java/util/Vector.html

Edited by alpha_omega
Link to comment
Share on other sites

  • 0
What does
System.out.println("Debugging endBalance:"+ getEndBalance());

return?

I guess nothing but still...

Edit: You're calling methods without having a receiver.

If you want to getEndBalance() then you'll have to tell the VM from which object. Just add values in front of the method. You'll have to loop over the array to get the values of each element of the array if that's what you want to achieve.

By the way, Vectors are much more elegant when dealing with arrays of objects:

http://java.sun.com/javase/6/docs/api/java/util/Vector.html

Nice.. worked great.. Didn't have to loop it i just did values[retirement2 -1].getEndBalance(); because i just wanted the end balance after x many years till retirement..

Again, thanks for the help.

Link to comment
Share on other sites

  • 0
Right so i created these classes a while ago and now i was asked to implement a gui interface.

This is when i discovered that my original code wasn't so great.. LOL

So basically my problem is, i am unable to get the endingBalance into the label on the panel..

using getEndBalance() i get a return value of 0.0 So basically it gives me the un initialized value instead of the value that goes to toString..

(same goes for the rest of the "get" methods..)

If anyone could help me on this i would really appreciate it.

Code:

http://www.nopaste.nl/?paste=1370 - AccountInformation

http://www.nopaste.nl/?paste=1371 - AccountPanel

http://www.nopaste.nl/?p=redirect&id=1372 - RetirementCalculator

Ive been stumped for a bit on this one,

Thanks again.

Thanks a lot for this useful posts..Hope we ll gain a lot from these links..

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.