File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return three values from a while loop

 
Rand Thomson
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I registered on this site since it's a friendly place for programming greenhorns of which I am definitely a newbie! I hope someone can help with this, I am using this while loop

and I want to return three values from the loop, the interest1, principle1, and loancounter. I've gotten an idea from another forum that I could do these calculations in a method and return an arraylist from there but I'm very confused on what this means. I can post my entire program if it's needed, but basically I'm at a bit of a loss how to create a class and method, or just a method for the existing class where I can return elements of an arraylist, from there I need to manipulate the arraylist but I think I can handle that. What I'm doing is creating an amoritization table for a loan here, and I can't figure out how to take my existing classes and create the loop to calculate the amoritization table without how I have the while loop currently setup? Does this make sense, been looking at this for about 12 hrs now and I'm having a difficult time moving forward... Thanks for any help provided!
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be convenient if you could give a brief description of your program and post the entire source code.
I dont know what is this code doing. The simplest solution that comes to my mind is that you can either dump the three values into an array (why ArrayList ?) and return a reference to the array.
OR (if its logical and suits your situation) you can make an Class with those three variables and methods to alter/access them and return a reference to that instance of that class.

wait a little more, i am sure you will get replies from more experienced people.
regards
rb
 
Rand Thomson
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the entire code, it's a gui so there's a lot of that there,


There is extraneous code in there as I've been looking at it and commenting out sections and whatnot. I get that the event listener is a void, so I can't return anything out of there, so how can I modify the code to produce the three variables per iteration of the while loop to create an array, or arraylist? I went with arraylist since the different variables will not create an array with a set value for the number of rows, though I suppose I could create the array like , right? Basically I want to take all the answers from the amoritization table for interest and principle paid, and sum them and then create a pie chart out of those answers. I think I can figure out how to do that, but I'm having a heck of a time figuring out how to return what I want from the while loop.
 
Rob Spoor
Sheriff
Pie
Posts: 20368
43
Chrome Eclipse IDE Java Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rand Thomson wrote:Here is the entire code, it's a gui so there's a lot of that there,
...
There is extraneous code in there

So trim it down and create an SSCCE. Leave out any component that's not relevant. Use shorter message strings. And keep it as small as possible.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47222
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch

 
Paul Clapham
Sheriff
Pie
Posts: 20161
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear in mind that I didn't read the big blob of code; but you don't "return a value from a loop" in Java. It would certainly be possible for the loop to assign a value to a variable which is declared outside the loop, and you might think of that as "returning a value". If that's what you had in mind, it would also be possible for the loop to assign values to three variables which are declared outside the loop.

However if that wasn't what you had in mind, go ahead and post the SSCCE.
 
Rand Thomson
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul, that will work great. How would I do that?
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Rand Thomson
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic