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

2011/6/11

On fixing 'Infect'

1
2
3
4
5
6
kiarocks kiarocks

2011/6/26

#
"cannot find constructor person"-im overwhelmed
danpost danpost

2011/6/26

#
You should already have one constructor:
public void Person()
{
    ...
}
to be called with
int randomX = Greenfoot.getRandomNumber(getWorld().getWidth()); 
int randomY = Greenfoot.getRandomNumber(getWorld().getHeight());
addObject(new Person(), randomX, randomY);
In the above, replace 'getWorld().getWidth()' with the actual value for the width of InfectWorld; and, replace 'getWorld().getHeight()' with the actual value for the height of InfectWorld Then: You need to create (add) ANOTHER constructor:
public void Person(int myAge, int myInfectStage)
{
    ...
}
to be called with
addObject(new Person(myAge, myInfectStage), randomX, randomY);
For the variables 'myAge' and 'myInfectStage', which values can be set to in any number of ways, I suggest:
int myAge = Greenfoot.getRandomNumber(100);
int myInfectStage = 0; // If you want to create a Person who is already infected, change '0', to '1' or '2' (whatever stage)
kiarocks kiarocks

2011/6/26

#
where should i put " int myAge = Greenfoot.getRandomNumber(100); int myInfectStage = 0; // If you want to create a Person who is already infected, change '0', to '1' or '2' (whatever stage) int x = Greenfoot.getRandomNumber(getWorld().getWidth()); // Use the actual width of InfectWorld, since you know it int y = Greenfoot.getRandomNumber(getWorld().getHeight()); // Again, use the actual height of InfectWorld "???
danpost danpost

2011/6/26

#
As far as
kiarocks wrote...
"cannot find constructor person"
Possibly you need to use 'Person' (with a capital P) or maybe you need parenthesis: 'new Person()' when calling.
kiarocks kiarocks

2011/6/26

#
acctually it is
cannot find symbol- constructor Person(int, int)
danpost danpost

2011/6/26

#
The first two lines:
int myAge = Greenfoot.getRandomNumber(100);  
    int myInfectStage = 0; // If you want to create a Person who is already infected, change '0', to '1' or '2' (whatever stage)
should be immediately before
addObject(new Person(myAge, myInfectStage), x, y);
when used in InfectWorld.class; and immediately before
getWorld().addObject(new Person(myAge, myInfectStage), x, y);
when used in Person.class. The 'int x' and 'int y' assignment statements are only used (before the same call of 'new Person(int, int)' when you are placing the Person randomly in the world. When a new (child birth) Person is added to the world, you would want to use the getX() and getY() functions on the mother to determine where to place the child in the world. And again, for 'int x' and 'int y', since you know the width and height of the world, use the actual numbers instead of 'getWorld().getWidth()' and 'getWorld().getHeight()'
danpost danpost

2011/6/26

#
Did you create a new constructor in Person?
public Person(int myAge, int myInfectStage)
{
    ...
}
kiarocks kiarocks

2011/6/26

#
yes
danpost danpost

2011/6/26

#
In what class did you write the code
addObject(new Person(int, int), x, y);
and show me the whole statement.
kiarocks kiarocks

2011/6/26

#
public void act() // In 'Person.class' { { if (isPregnant) { howLongTillDue--; if (howLongTillDue == 0) { int myAge = Greenfoot.getRandomNumber(100); int myInfectStage = 0; getWorld().addObject(new Person(0, 0), getX(), getY()); isPregnant = false; } } }
kiarocks kiarocks

2011/6/26

#
erm, means
    int myAge = Greenfoot.getRandomNumber(100);    
        int myInfectStage = 0; // If you want to create a Person who is already infected, change '0', to '1' or '2' (whatever stage)  
is in world class
danpost danpost

2011/6/26

#
Try eliminating 'getWorld().' in the call statement, if that does not work, check you brackets (it looks like you have an extra one before 'if (isPregnant)'
danpost danpost

2011/6/26

#
I will have to test it out (later); I have to go right now; but, will be back in a few hours!
kiarocks kiarocks

2011/6/26

#
note above!
kiarocks kiarocks

2011/6/26

#
oh, ok
There are more replies on the next page.
1
2
3
4
5
6