0

我的其他一切都是正确的,但由于某种原因,这给我带来了问题。我想实现一个名为 populate() 的方法。我想在构造函数中被调用。我希望它为每种类型的对象创建随机数量的对象的方法。这是我的代码。我的错误是“* strong text *constructor yellowish in class yellowish cannot be apllied to given types. required: int found: not argument reason: actual and form argument list in lengthly different.

public class FishWorld extends World
{

    /**
     * Constructor for objects of class FishWorld.
     * 
     */
    public FishWorld() 
    {

        super(600, 400, 1);

        populate();
        populate2();
        populate3();
    }


    public void populate()
    {
        int randX;
        int randY;

        for(int i = 0; i < 5; i++)
        {
            YellowFish yf = new YellowFish();
            randX = Greenfoot.getRandomNumber ( getWidth() );
            randY = Greenfoot.getRandomNumber( getHeight() );
            addObject(yf, randX, randY);
        }
    }
    public void populate2()
    {
        int randX;
        int randY;
        for(int i = 0; i < 5; i++)
        {
            GreenFish gf = new GreenFish();
            randX = Greenfoot.getRandomNumber ( getWidth() );
            randY = Greenfoot.getRandomNumber( getHeight() );
            addObject(yf, randX, randY);
        }
    }
    public void populate3()
    {
        int randX;
        int randY;
        for(int i = 0; i < 5; i++)
        {
            StripeFish sf = new StripeFish();
            randX = Greenfoot.getRandomNumber ( getWidth() );
            randY = Greenfoot.getRandomNumber( getHeight() );
            addObject(yf, randX, randY);
        }
    }
}
4

1 回答 1

1

empty parameter看来您在 YellowFish 类中没有构造函数。您可能要添加:

public YellowFish() {
// ... your code here
}

在 YellowFish 类中。

于 2012-04-23T02:29:58.197 回答