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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

storing data from a Java Loop

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Bradley Jordan
greenhorn
Member # 143948
posted Yesterday 8:09 PM
--------------------------------------------------------------------------------
I am currently taking a Java class. I have a project that wants me to repeat the output within a JOptionPane.
here is my code so far

public double valueOfMoney(double amountOfMoney, int lengthOfTime)
{
double x = amountOfMoney;
int y = lengthOfTime;
int loopcount = 0;
String allString;
while (loopcount < y)
{

x = x * (1 + constant);
x = (int)(x * 100) / 100.0;
loopcount += 1;
allString = "The amount at end of year " + loopcount + " is $" + x;
JOptionPane.showConfirmDialog(null, allString + "\n" + x, "Investment Resutls",JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE);


}
return x;
}

This prints out the results in the pane but it goes to another pane what I want is something like this all withing the same pane.

The amount of year 1 is $x.xx
The amount of year 2 is $x.xx
etc.....

This is possible? Can it be done from the same method? I have taken the JOPtionPane out of the loop but it only gives me the last iteration through. What I need is a way to store the data for each iteration and than a way to print it all out at once.

Please help. I greatly appreicate any help.



Thanks,
Bradley Jordan
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please don't post the same question twice.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Indeed. I am closing this topic - please refer to this thread for followups.
 
    Bookmark Topic Watch Topic
  • New Topic