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 10:30
You have a large, late-model pick-up truck with a rear seat. the pick-up truck weighs 6,500 pounds. the florida seat belt law
Answers: 1
question
Computers and Technology, 22.06.2019 18:30
List the five on-board vehicle subsystems
Answers: 1
question
Computers and Technology, 23.06.2019 09:00
Before you record your own voice, you should a. record other people's voices b. warm up and practice difficult names c. listen to your favorite songs d. read a transcript of a good radio news segment
Answers: 1
question
Computers and Technology, 23.06.2019 23:30
Match the following errors with their definitions. a. #name b. #value c. #ref d. 1. when a formula produces output that is too lengthy to fit in the spreadsheet cell 2. when you enter an invalid cell reference in a formula 3. when you type text in cells that accept numeric data 4. when you type in a cell reference that doesn’t exist
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: 13722363