subject

Currently, a fox will eat at most one rabbit at each step. Modify the findFood method so that rabbits in all adjacent locations are eaten at a single step. Asssess the impact of this change on the results of the simulation. Note that findFood method currently returns the location of the single rabbit that is eaten, so you will need to return the location of the one of the eaten rabbits in your version. However, don’t forget to return null if there are no rabbits to eat.
Original Code
01
private Location findFood()
02
{
03
List adjacent = field. adjacentLocations(location);
04
Iterator it = adjacent. iterator();
05
while(it. hasNext()) {
06
Location where = it. next();
07
Object animal = field. getObjectAt(where);
08
if(animal instanceof Rabbit) {
09
Rabbit rabbit = (Rabbit) animal;
10
if(rabbit. isAlive()) {
11
rabbit. setDead();
12
foodLevel = RABBIT_FOOD_VALUE;
13
return where;
14
}
15
}
16
}
17
return null;
18
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:30
Melissa needs to add a topic to an email that she will send to her teacher. choose the name of the field where she should type her topic.
Answers: 2
question
Computers and Technology, 23.06.2019 17:20
What is the best assassins creed game?
Answers: 2
question
Computers and Technology, 23.06.2019 18:40
How does is make you feel when you're kind to others? what are some opportunities in your life to be more kind to your friends and loved ones? imagine a world where kindness has be outlawed. how would people act differently? would your day-to-day life change significantly? why or why not?
Answers: 2
question
Computers and Technology, 24.06.2019 00:30
Match the sentence fragment in the first column with the appropriate ending in the second column. a little per favore?
Answers: 1
You know the right answer?
Currently, a fox will eat at most one rabbit at each step. Modify the findFood method so that rabbit...
Questions
question
Physics, 27.03.2020 05:27
question
Social Studies, 27.03.2020 05:28
Questions on the website: 13722367