Mahesh Bamane wrote:Say I've 3 currencies A, B and C.
I'm storing them in a table using 3 columns currency_1, currency_2, and conversion rate.
For example;
C_1->C_2 Rate
A->B 0.45
B->C 1.25
C->A 1.60
Like this I may have N number of currencies in the DB.
As Dennis said, think about creating a class of your own for that in Java (Currency?).
I just find out the number of combinations such as A->B->C and again C->A, in the database. (A->B->C->A)
So while doing this in java programming laguage which data-structure can be used? and how this can be resolved.
Well, to answer your 2nd question first: either a Map ( java.util.Map ) or a Set ( java.util.Set ),
but you need a class first.
And, while there's no particular problem with your idea of holding all combinations, you do have a couple of issues:
1. How do you eliminate duplicates? Personally, I'd think that $→Yen is the same as 1/(Yen→$), wouldn't you agree?
2. The sheer volume of combinations. Say you have 20 currencies: how many combinations can you have?
There is, however, a simple way of holding your currencies that
doesn't involve combinations at all. Can you think what it is? (Hint: it involves a
2-step conversion).
HIH
Winston