• 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
  • 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 values in an array and accessing them elsewhere in the program

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm writing a basic conversion program for celsius and fahrenheit temperatures. These values are input into a textfield and then converted in a simple actionPerformed method.

Basically, I'm now struggling with the array part. How do I add these values for the temperatures to an array so I can then access them elsewhere in the program.

My code for the actionPerformed method is as follows,


I'm basically trying to save the temperature values for each user session, and link them to a forward and backward button. These values do not have to be saved after the user exits the program.

Any advice or help appreciated!
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Better use a java bean for storing these kinds of things. I mean temperature,as well as other details of the user. If you have one similar bean then write getter and setter methods for storing this temperature.


Whats the need of arraylist?? You said you have to store only 1 single temperatiure value.
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I need to store as many values as the user inputs and converts during the run of the program.

eg: a user could input 10 degrees celsius and convert it to a fahrenheit value, then 25 degrees celsius and convert that and so on. They would then need to be able to go backwards and forwards through these values.

Therefore, I just assumed an array was the best way to store and access these values, but I'm not sure how to implement this solution.

Any ideas or help appreciated!
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like an ArrayList might be a better tool than an array. I say this because you don't know exactly how many numbers you will be storing. Most likely this ArrayList should be a member variable somewhere, but I'm not sure which class it should belong to since you haven't posted any description of your design.

Layne
 
reply
    Bookmark Topic Watch Topic
  • New Topic