Question: Help to implement the ATV chooseDirection method using a single statement. You may use private helper methods but any private helper methods used must also

Help to implement the ATV chooseDirection method using a single statement. You may use private helper methods but any private helper methods used must also include a single statement: return ;.

Hint: Use the Stream API along with lambda expressions and/or method references to implement this method as single statements.

package model;

import java.util.Map;

public class Atv extends AbstractVehicle {

/** Dead time for a atv.*/

private static final int DEATH_TIME= 25;

public Atv(final int theX, final int theY, final DirectiontheDirection) {

super(theX, theY, theDirection, DEATH_TIME);

}

public DirectionchooseDirection(final Map theNeighbors) {

Directiondirection = Direction.random();

while (theNeighbors.get(direction) == Terrain.WALL

|| direction == getDirection().reverse()) {

direction = Direction.random();

}

return direction;

}

public boolean canPass(final TerraintheTerrain, final LighttheLight) {

boolean allowedToPass = false;

if (theTerrain != Terrain.WALL) {

allowedToPass = true;

}

return allowedToPass;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!