Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #2154

Re: Need Help with some code. Not sure why it's not working. Can someone please take a look?

Newsgroups comp.lang.java.help
Date 2012-10-12 22:42 -0700
References <b643cfda-6dda-4d8d-aa1a-1ae01740291b@googlegroups.com>
Message-ID <5abe60cc-734f-40ab-9e07-5296e81be477@googlegroups.com> (permalink)
Subject Re: Need Help with some code. Not sure why it's not working. Can someone please take a look?
From Lew <lewbloch@gmail.com>

Show all headers | View raw


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

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Need Help with some code. Not sure why it's not working. Can someone please take a look? ortizgabriel79@gmail.com - 2012-10-12 19:10 -0700
  Re: Need Help with some code. Not sure why it's not working. Can someone please take a look? Lew <lewbloch@gmail.com> - 2012-10-12 22:42 -0700
  Re: Need Help with some code. Not sure why it's not working. Can someone please take a look? Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-13 09:23 -0400
  Re: Need Help with some code. Not sure why it's not working. Can someone please take a look? John Dildy <jdildy85@gmail.com> - 2012-12-02 13:56 -0800

csiph-web