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


Groups > comp.lang.java.help > #2153 > unrolled thread

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

Started byortizgabriel79@gmail.com
First post2012-10-12 19:10 -0700
Last post2012-12-02 13:56 -0800
Articles 4 — 4 participants

Back to article view | Back to comp.lang.java.help


Contents

  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

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

Fromortizgabriel79@gmail.com
Date2012-10-12 19:10 -0700
SubjectNeed Help with some code. Not sure why it's not working. Can someone please take a look?
Message-ID<b643cfda-6dda-4d8d-aa1a-1ae01740291b@googlegroups.com>
It keeps saying that type ArrayList is not generic and cannot be parametierized with arguments <Double> 

AND that Parameterized types are only available if source type is 5.0

I'm using Eclipse to comiple everything. 





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 };
    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>();
    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";

[toc] | [next] | [standalone]


#2154

FromLew <lewbloch@gmail.com>
Date2012-10-12 22:42 -0700
Message-ID<5abe60cc-734f-40ab-9e07-5296e81be477@googlegroups.com>
In reply to#2153
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

[toc] | [prev] | [next] | [standalone]


#2155

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2012-10-13 09:23 -0400
Message-ID<k5bq15$rl6$1@dont-email.me>
In reply to#2153
On 10/12/2012 10:10 PM, ortizgabriel79@gmail.com wrote:
> It keeps saying that type ArrayList is not generic and cannot be parametierized with arguments <Double>
>
> AND that Parameterized types are only available if source type is 5.0
>
> I'm using Eclipse to comiple everything.
> [...]

     Perhaps your project is set up for pre-5.0 Java.  I'm not
an Eclipse user, but two things to check are

     - Do your project setting specify a particular Java version?
       If so, and if you're using an ancient Java[*], consider
       moving to a more recent edition.

     - Is your Java installation itself ancient?  That is, when
       the compiler looks for Java's own classes does it find
       something from the Dark Ages[*]?

     [*] J2SE 5 brought generics to Java eight years ago, went
to end-of-life status four years ago, and became unsupported
three years ago.  The rest of the world is now on J2SE 7, with
J2SE 8 expected next year.  "Be not the first by whom the new
is tried / Nor yet the last to set the old aside."

-- 
Eric Sosman
esosman@comcast-dot-net.invalid

[toc] | [prev] | [next] | [standalone]


#2309

FromJohn Dildy <jdildy85@gmail.com>
Date2012-12-02 13:56 -0800
Message-ID<56c78996-5f19-49d6-a77c-22e421dbcbbb@googlegroups.com>
In reply to#2153
From what I am seeing Gabriel is that you don't have:

public class <nameofclassgoeshere>

other than that I don't see any other problems

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.help


csiph-web