java 错误提示小问题

来源:百度知道 编辑:UC知道 时间:2024/09/19 16:27:21
这个是我写的java程序,有2个报错,但是不知道该怎么解决~~
请大家帮忙看下~~谢谢

interface ComputerWeight
{
public double ComputerWeight();
}

class Television implements ComputerWeight
{
public void ComputerWeight(double weight)
{
this.weight=weight;
}
}

class Computer implements ComputerWeight
{
public void ComputerWeight(double weight)
{
this.weight=weight;
}
}

class WashMachine implements ComputerWeight
{
public void ComputerWeight(double weight)
{
this.weight=weight;
}
}

class Car
{
ComputerWeight[] goods;
double totalWeights=0;
Car(ComputerWeight[] goods)
{
this.goods=goods;
}
public double getTotalWeights()
{
totalWeights=0;
for(ComputerWeight item:goods)
{
totalWeights=totalWeights+item.ComputerWeight();
}
return totalWeights;
}
}<

你这个程序,怎么可能只报二处错啊,不只吧。interface ComputerWeight
{
public double ComputerWeight();
}

class Television implements ComputerWeight
{
public void ComputerWeight(double weight)
{
this.weight=weight;
}
}
这个地方就不地,你的 ComputerWeight(double weight)有参数,你的接口是没有传参数的,怎么可能这个地方不报错呢???

你最大的错误,就是你每一个实现接口的类,虽然实现了接口,但是接口里的方法你全都重写了。java里当你实现一个接口时你必须完全实现此接口的方法。并且此方法要和接口中的方法完全一一对应。所以你这个程序根本不能运行。不符号java语言的基础逻辑。

Java 实现一个借口,那么就要实现借口里面的所有方法,实现的话方法名什么的都要一样!

变量名怎么还用汉字了?
还有要区分大小写的 类名car首字母应该大写