?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Testing: Expected Results for moveDog Method

APCSA-1NVVE6

Consider the following method in a Dog class.

/** 
 * Pre-condition: dog is in an unbounded area with nothing in its way
 * The parameters are executed in the order they are listed.
 * @param move - moves forward this number of spaces (if positive number) 
 *               or backwards this number of spaces (if negative number) 
 * @param turn - turns 90 degrees to right (if positive odd number) or 90 
 *               degrees to left (if negative odd number).  Does not 
 *               turn if even number.
 * @param bark - if true then dog barks, else dog does not bark
 * @return number of degrees that dog turns (negative means counter- 
 *               clockwise and positive means clockwise)
 */
public int moveDog(int move, int turn, boolean bark)
{
    // code not shown
}

What do you expect this method to do when the following test scenario is executed?

moveDog(-4, 11, true);
A

The dog moves backward 4 spaces, turns 90 degrees counterclockwise, and barks. The method returns -90.

B

The dog moves forward 4 spaces, turns 90 degrees clockwise, and barks. The method returns 90.

C

The dog moves backward 4 spaces, does not turn, and barks. The method returns 0.

D

The dog moves backward 4 spaces, does not turn, and does not bark. The method returns 0.

E

The dog moves backward 4 spaces, turns 90 degrees clockwise, and barks. The method returns 90.