• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

assigning values to a list of variables

 
Rancher
Posts: 648
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have a list of say 10 currencies and am concerned about an amount associated with each

Initially I zero all currency amounts, then
In my code I
1) ascertain which currency I am currently dealing with
2) add or subtract a certain amount to/from that currency amount

If I have the list of currencies in a string such that string[0] is the first currency and string[9] is the last
and suppose each string has two components, namely (i) name and (ii) amount
After 1) above I may have USD for instance
How do I quickly ascertain which of string[0] to string[9] is the USD + amount string ?

Bob M
 
Marshal
Posts: 76818
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't. That sounds a really error‑prone way to do it. The last thing you want to do is try to pull Strings apart.
I suggest you need a Currency class, then you can make a Currency[] array.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bob Matthews wrote:I have a list of say 10 currencies and am concerned about an amount associated with each


And further to what Campbell said, I'd say that a list (or array) is NOT what you want. If you have a set of currencies, and an amount associated with each one, I'd say that a Map would be a much better way to store them.

Presuming you're familiar with Maps that is.

Winston
 
Campbell Ritchie
Marshal
Posts: 76818
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are right about Maps. A bit more thought would have led me to the same conclusion.
 
Bob Matthews
Rancher
Posts: 648
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Winston & Campbell

I know nothing about Maps but will look into them

regards

Bob M
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic