Java方法不允许双重?

时间:2011-05-07 16:05:55

标签: java

好的,所以这是我的两个班级:

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;
}

我是从以下地方打电话来的:

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

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

我收到错误:找不到符号方法setArray(double)??

编辑:

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;
}`

谢谢!

1 个答案:

答案 0 :(得分:1)

您没有定义newList。无论定义哪个类setArray()都需要用于从另一个类访问setarray()

实施例: -

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

}

更新

newList被定义为实现List接口的ArrayList。它没有名为setArray()的方法。看看我上面的例子。为了从另一个类调用方法,您必须首先构造该对象。

希望这能澄清它。