Type of collection to use for 3 row values, 2 of which must be multiplied
i am returning results from a sql query which contains multiple rows of three columns. Column1(a rate) must be multiplied by column2(a n开发者_如何学Pythonumerical value). Column 3 consists of five different possible values. Each value will indicate a condition that column1 and column2 must adhere to( basically column3 will be another value (like an exchange rate)- but it has not yet been determined, so I would like to group this value with the result of the other two. Obviously a collection of some sort ought to be used, but i am not sure which will allow me to efficiently deal with multiplying column1 by column2 and noting the value for column3 and multiplying this at a later date. So far, I have something like this: (obviously ill probably need a for loop)
double value= "column1";
double rate= "column2";
double currency= "column3";
Finalamount setValue(value);
Finalamount setRate(rate);
Finalamount setCurrency(currency);
Collection <Finalamount> col = new ArrayList();
You ought to write a custom class that abstracts all this away from clients. It'll document and encapsulate what needs to be done and simply handles it so it's all set when clients get the query results back.
Looks like you're already on the right track. Just type your array list and give it a better name:
Collection <Finalamount> finalAmounts = new ArrayList<Finalamount>();
精彩评论