double - Can't seem to get .doubleValue() to work (I have the latest version of Java) -


so having problem method created, called averagecost(). error is:

    exception in thread "main" java.lang.error: unresolved compilation problem:  method doublevalue() undefined type double  @ queue.averagecost(queue.java:38) @ queue.main(queue.java:47) 

and tried adding double value double object didn't work. found .doublevalue method can't work. added code (everything else works fine) in case clears up. have been stuck on couple days while working on other stuff please ):

    import java.util.linkedlist;     public class queue<double> {  private linkedlist<double> linklist; private string symbol; private string name; private int shares; private double price;  public queue(string symbol2, string name2, int shares2, double price2) { //so far, have linkedlist works     linklist = new linkedlist<double>();     shares = shares2;     price = price2;     symbol = symbol2;     name = name2;     bigadd(shares, price); }  public void add(double e) {     linklist.add(e); }  public double take() {     return linklist.poll(); }         public void bigadd (int shares2, double price2) {      while(shares2>0) {         linklist.add(price2);         shares2--;     } }  public double averagecost(int shares2) {     double average = 0;     int sizer = 0;     while(sizer < shares2) {         average = average + linklist.poll().doublevalue(); //this problem lies         sizer++;     }     average = average/shares2;     return average; }     } 

your mistake comes class declaration.

formal parameter of generic may t:

public class queue<t> { 

now see t has no method named doublevalue because haven't constrained it.

the following want:

import java.util.linkedlist;  public class queue<t extends number> {     private final linkedlist<t> linklist;    private final int           shares;    private final t             price;     public queue( int shares2, t price2 ) {       linklist = new linkedlist<>();       shares   = shares2;       price    = price2;       bigadd( shares, price );    }     public void add( t e ) {       linklist.add(e);    }     public t take() {       return linklist.poll();    }     public void bigadd( int shares2, t price2 ) {       while(shares2>0) {          linklist.add(price2);          shares2--;       }    }     public double averagecost( int shares2 ) {       double average = 0;       int sizer = 0;       while( sizer < shares2 ) {          final t v = linklist.poll();          average = average + v.doublevalue();          sizer++;       }       average = average/shares2;       return average;    } } 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -