• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

return three values from a while loop

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22800
131
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79699
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch

 
Marshal
Posts: 28295
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul, that will work great. How would I do that?
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Rand Thomson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic