wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes return three values from a while loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "return three values from a while loop" Watch "return three values from a while loop" New topic
Author

return three values from a while loop

Rand Thomson
Greenhorn

Joined: Apr 10, 2011
Posts: 4
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

Joined: Jan 21, 2011
Posts: 637

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

SCJP 6. Learning more now.
Rand Thomson
Greenhorn

Joined: Apr 10, 2011
Posts: 4
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

Joined: Oct 27, 2005
Posts: 19722
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
. . . and welcome to the Ranch

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

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

Joined: Apr 10, 2011
Posts: 4
Paul, that will work great. How would I do that?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11420
    
  16



There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rand Thomson
Greenhorn

Joined: Apr 10, 2011
Posts: 4
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: return three values from a while loop