【发布时间】:2015-07-22 17:43:23
【问题描述】:
我正在处理一个项目,该项目有一个名为 Items 的类和一个名为 totals 的方法,该方法计算 Items 对象数组的总计。 出于某种原因,它看不到项目,我知道我遗漏了一些简单或明显的东西,但我就是想不通。蚂蚁帮助将不胜感激。
public void totals(){
int index=0;
for (Iterator it = items.iterator(); it.hasNext();) {
Items i = it.next();
double itotal;
itotal = items.get(index).Items.getTotal();
}
}
这里是 Items 类
public class Items {
public String name;//instance variable for item name
public int number;//instance variable for number of item
public double price;//instance variable for unit price
public double total;//instance variable for total
Items(String name,int number,double price){
this.name=name;
this.number=number;
this.price=price;
total=number*price;
}
public void setName(String name){
this.name=name;
}
public void setNumber(int number){
this.number=number;
}
public void setPrice(double price){
this.price=price;
}
public void setTotal(){
total=number*price;
}
public String getName(){
return name;
}
public int getNumber(){
return number;
}
public double getTotal(){
return total;
}
public double getPrice(){
return price;
}
提前感谢您的帮助。
【问题讨论】:
-
你能粘贴任何正在发生的错误吗? “它看不到项目”不是非常技术性或特定于问题。
-
这是我在线程“main”java.lang.RuntimeException 中编译异常时得到的错误:无法编译的源代码 - 错误的符号类型:ReciptPrinter.ReciptPrinter 的 java.lang.Object.getTotal。 Totals(ReciptPrinter.java:52) at ReciptPrinter.ReciptPrinter.main(ReciptPrinter.java:36) Java 结果:1 IDE 给出此错误找不到符号符号:方法 getTotal() 位置:对象类型的变量项