This site requires JavaScript, please enable it in your browser!
Greenfoot back
Mr.Murphey
Mr.Murphey wrote ...

2013/12/4

<identifier> Expected

Mr.Murphey Mr.Murphey

2013/12/4

#
1
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
2
3/**
4* Write a description of class FishWorld here.
5 * 
6 * @author (your name) 
7 * @version (a version number or a date)
8 */
9public class FishWorld extends World
10{
11
12    /**
13     * Constructor for objects of class FishWorld.
14     * 
15     */
16    public FishWorld()
17    {    
18        // Create a new world with 400x400 cells with a cell size of 1x1 pixels.
19        super(400, 400, 1);
20       randomFish(10);
21        randomPred(1);
22        randomSuperPred(1);
23        spawnPredator(5);
24    }
25
26    public void randomFish(int howMany)
27    {
28        for(int i=0;i<howMany;i++)
29        {
30            Fish f1=new Fish();
31            int X=Greenfoot.getRandomNumber(getWidth());
32            int Y=Greenfoot.getRandomNumber(getHeight());
33            addObject(f1,X,Y);
34        }
35    }
36
37    public void randomPred(int howMany)
38    {
39        for(int i=0;i<howMany;i++)
40        {
41            PredatorFish pf1=new PredatorFish();
42            int X=Greenfoot.getRandomNumber(getWidth());
43            int Y=Greenfoot.getRandomNumber(getHeight());
44           addObject(pf1,X,Y);
45        }
46    }
47
48    public void randomSuperPred(int howMany)
49    {
50        for(int i=0;i<howMany;i++)
51        {
52            SuperPredatorFish spf1=new SuperPredatorFish();
53            int X=Greenfoot.getRandomNumber(getWidth());
54            int Y=Greenfoot.getRandomNumber(getHeight());
55            addObject(spf1,X,Y);
56        }
57    }
58    public void setInt(int t);
59    public class PredatorFish extends Actor
60    {
61        private int FishEaten;
62        FishEaten=1;
63    }
64}
The identifier is on line 62 and i have no idea how to fix it.
Mr.Murphey Mr.Murphey

2013/12/4

#
oops didn't know it would auto #.
Gevater_Tod4711 Gevater_Tod4711

2013/12/4

#
The code in line 62 is not placed in any method. It's just in the class PredatorFish. You can only declare global variables this way. If you want the variable FishEaten to be 1 when you create a new class you can delete line 62 and change line 61 to 'private int FishEaten = 1;'
Mr.Murphey Mr.Murphey

2013/12/10

#
Thank you
You need to login to post a reply.