我在java中创建了这两个文件但它们没有编译。出现此错误:
找不到符号C02FootprintV1“。
为什么程序不识别对象?我是新手。
我该如何解决这个问题?
public class CO2FootprintV1 {
private double myGallonsUsed;
private double myTonsCO2;
private double myPoundsCO2;
CO2FootprintV1(double gals) {
myGallonsUsed = gals;
}
public void calcTonsCO2() {
myTonsCO2 = myGallonsUsed * 0.878;
}
public double getTonsCO2() {
return myTonsCO2;
}
public void convertTonsToPoundsCO2() {
myPoundsCO2 = myTonsCO2 * 220462262;
}
public double getPoundsCO2() {
return myPoundsCO2;
}
}
public class CO2FootprintV1Tester {
public static void main(String[] args) {
double gals;
double tonsCO2, poundsCO2;
gals = 1300;
CO2FootprintV1 object = new C02FootprintV1(gals);
object.calcTonsCO2();
tonsCO2 = object.getTonsCO2();
object.convertTonsToPoundsCO2();
poundsCO2 = object.getPoundsCO2();
}
}
答案 0 :(得分:2)
在线
CO2FootprintV1 object = new C02FootprintV1(gals);
你右边有C02
(见零),你的意思是
CO2FootprintV1 object = new CO2FootprintV1(gals);
或CO2
(见二)。此外,您应该考虑工具提供的错误消息可能是正确的。
答案 1 :(得分:1)
只需改变:
CO2FootprintV1 object = new C02FootprintV1(gals);
为:
CO2FootprintV1 object = new CO2FootprintV1(gals);
这就是为什么要有良好的命名练习很重要。
答案 2 :(得分:1)
你输入“0”(cero)而不是“O”(字母):
CO2FootprintV1 object = new C02FootprintV1(gals);
试试这个:
CO2FootprintV1 object = new CO2FootprintV1(gals);