Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the moveAnimal method in AnimalInterface. This move has several steps, whi

ID: 3694476 • Letter: W

Question

Write the moveAnimal method in AnimalInterface. This move has several steps, which can all be included in the method, or you can add private methods for each step:

STEP 1) Select the move (of type eMove) which is in the exact opposite direction from the closest Terrier. For example, if the Terrier is left on the same row, move right. If the Terrier is below on the same column, move up. If the Terrier is above and right, move down and left. If the Terrier is below and right, move up and left, and so on.

//
// DO NOT MODIFY BELOW
//
private int currentRow;
private int currentCol;
private int previousRow = -1;
private int previousCol = -1;
private int closestRow;
private int closestCol;
private char[][] field;

// Initializes position and field
public Squirrel(int row, int col, char[][] field){
this.currentRow = row;
this.currentCol = col;
this.field = field;
}

// Getters
public int getCurrentRow(){ return currentRow; }
public int getCurrentCol(){ return currentCol; }
public int getPreviousRow(){ return previousRow; }
public int getPreviousCol(){ return previousCol; }
public int getClosestRow(){ return closestRow; }
public int getClosestCol(){ return closestCol; }
//
// DO NOT MODIFY ABOVE
//

// Move squirrel according to the rules
public void moveAnimal() {

eMove move;

// Store previous position
previousRow = currentRow;
previousCol = currentCol;

// TO DO: replace with code to select move (Step 1)
move = eMove.RIGHT;

Explanation / Answer

Can you let me know whether I should use the above code or implement a new program to create Animal interface with moveAnimal() method.