无法将城市转换为可汇总

时间:2018-10-12 21:10:01

标签: java

因此,我应该使用“汇总”界面来汇总城市人口。我已经盯着它看了一个小时,但仍然找不到我的错误。请帮忙!

这是我的测试员

public class SummableTester extends ConsoleProgram
{
    public void run()
    {
        City cookie = new City("Coookie", 20000);
        City taco = new City("Taco", 10000);
        System.out.println(taco.getValue());
    }
}

城市等级:

    public class City
    {
    private String name;
    private int population;

    public City(String name, int population)
    {
        this.name = name;
        this.population = population;
    }

    public String getName()
    {
        return this.name;
    }
    public int getValue()
    {
        return this.population;
    }
    public int add(Summable other)
    {
        return getValue() + other.getValue();
    }
}

可总结:

public interface Summable
{
    public int add(Summable other);

    public int getValue();
}

1 个答案:

答案 0 :(得分:0)

您在Summable类中实现了City界面,但是忘记在城市类中包含implements Summable

public class City implements Summable {


}