开发者

Java method not allowing a double?

开发者 https://www.devze.com 2023-03-04 13:48 出处:网络
Alright, so here\'s my two classes: public void setArray(double anyValue){ totalTax=0.0; total=0.0; for(int indexc=0; indexc < costArray.size(); indexc++){

Alright, so here's my two classes:

public void setArray(double anyValue){
    totalTax=0.0;
    total=0.0;
    for(int indexc=0; indexc < costArray.size(); indexc++){
       System.out.println("Enter the item name: ");
       String anyName = keybd.next();
       itemArray.add(anyName);
       System.out.println("Enter the item cost: ");
       double cost = Double.valueOf(keybd.next()).doubleValue();
       costArray.add(" " + cost);
       totalTax = totalTax + (cost * anyValue);
       total = total + cos开发者_如何学JAVAt;
    }
    totalTax = totalTax;
    total = total;
}

And I'm calling it from:

public TaxClass(int anyAmount)
{
    newList = new ArrayList<Input>(anyAmount);
}

    public void addItems(double anyTax){
    newList.setArray(anyTax);
    System.out.println("Item added!");
   }

I'm getting the error:cannot find symbol method setArray(double) ??

EDIT:

public void setArray(double anyValue){
 totalTax=0.0;
total=0.0;
for(int indexc=0; indexc < costArray.size(); indexc++){
   System.out.println("Enter the item name: ");
   String anyName = keybd.next();
   itemArray.add(anyName);
   System.out.println("Enter the item cost: ");
   double cost = Double.valueOf(keybd.next()).doubleValue();
   costArray.add(" " + cost);
   totalTax = totalTax + (cost * anyValue);
   total = total + cost;
}
totalTax = totalTax;
total = total;
}`

Thanks!


You do not have newList defined. Whatever class setArray() is defined at needs to be used to access setarray() from another class.

Example:-

Class Foo{

public void setArray(double anyValue){
//your code
}
}

Class Bar{

public void addItems(double anyTax){
    Foo foo = new Foo();
    foo.setArray(anyTax);
    System.out.println("Item added!");
}

}

UPDATE

newList is defined as an ArrayList which implements the List interface. It does not have a method called setArray(). Take a look at my example above. In order to invoke a method from another class you will have to construct that object first.

Hope this clarifies it.

0

精彩评论

暂无评论...
验证码 换一张
取 消