Re: Need Help with some code. Not sure why it's not working. Can
someone please take a look?
Gabriel Ortiz wrote:
It keeps saying that type ArrayList is not generic and cannot be parametierized with arguments <Double>
Which 'ArrayList' are you using?
AND that Parameterized types are only available if source type is 5.0
What Java version are you using?
How do you have your Eclipse project settings set for Java compilation?
I'm using Eclipse to comiple everything.
And what is Eclipse using?
public static void main(String args[]) {
DecimalFormat df = new DecimalFormat("###,###.00");
double[] PRICE_ARRAY = { 10.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15, 3.98 };
Java conventions call for the use of all-uppercase variable names only
for constant variables, and likewise reserve the use of underscores
in names for that case.
double[] QUANTITY_ARRAY = { 4.0, 8.5, 6.0, 7.35, 9.0, 15.3, 3.0, 5.4, 2.9, 4.8 };
ArrayList<Double> priceList = new ArrayList<Double>();
Best practice usually is to type the variable to the interface.
ArrayList<Double> quantityList = new ArrayList<Double>();
ArrayList<Double> amountList = new ArrayList<Double>();
for (int i=0; i < 10; i++){
priceList.add(new Double(PRICE_ARRAY[i]));
quantityList.add(new Double(QUANTITY_ARRAY[i]));
}
result = "";
for (int i = 0; i < 10; i++) {
amountList.add((Double.valueOf(priceList.get(i).toString())) * (Double.valueOf(quantityList.get(i).toString())));
result += String.valueOf(i+1) + ") "
+ new String(df.format(priceList.get(i))) + " * "
+ new String(df.format(quantityList.get(i))) + " = "
+ new String(df.format(amountList.get(i))) + "\n";
You know if you only give us half the data we can only provide half an
answer, right?
In this case, set your Eclipse preferences to use the correct Java syntax.
--
Lew