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 04:00
Which of the following kinds of programs displays an online advertisement in a banner or pop-up window on webpages, email, or other internet service? e
Answers: 2
question
Computers and Technology, 22.06.2019 15:10
David is in week 3 of his current ashford course and has a paper due by monday night at midnight. he has finished everything but the concluding paragraph. as he boots up his computer to work on it, he sees a flash across the screen and then the screen goes black. he begins to panic as he tries desperately to turn the laptop back on. david should have saved his work on what kind of portable device?
Answers: 2
question
Computers and Technology, 23.06.2019 00:30
Which of the following would you find on a network
Answers: 3
question
Computers and Technology, 23.06.2019 15:30
The song about casey jones a railroad engineer who gives his life on the job would most likely gall under the folk song category of? a-work song b-nonsense song c-religious song d-ballad
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
Questions on the website: 13722361