22.1k views
3 votes
In the simulation, player 2 will always play according to the same strategy. The number of coins player 2 spends is based on what round it is, as described below. (a) You will write method getPlayer2Move, which returns the number of coins that player 2 will spend in a given round of the game. In the first round of the game, the parameter round has the value 1, in the second round of the game, it has the value 2, and so on. The method returns 1, 2, or 3 based on the following rules. If round is divisible by 3, then return 3. If round is not divisible by 3 but is divisible by 2, then return 2. If round is not divisible by 3 and is not divisible by 2, then return 1. Complete method getPlayer2Move below by assigning the correct value to result to be returned.

User SMAKSS
by
4.0k points

2 Answers

1 vote

Final answer:

The getPlayer2Move method returns 1, 2, or 3 based on the given rules.

Step-by-step explanation:

The method getPlayer2Move returns 1, 2, or 3 based on the rules given in the question. If the round number is divisible by 3, the method returns 3. If the round number is not divisible by 3 but is divisible by 2, the method returns 2. If the round number is not divisible by 3 and not divisible by 2, the method returns 1. For example, if the round number is 4, which is divisible by 2 but not divisible by 3, the method would return 2.

User Diego Castro
by
3.5k points
1 vote

Final answer:

To determine the number of coins that player 2 will spend in a given round of the game, check the rules based on the value of the round: divisible by 3 = 3 coins, divisible by 2 but not by 3 = 2 coins, not divisible by 3 and not divisible by 2 = 1 coin.

Step-by-step explanation:

To determine the number of coins that player 2 will spend in a given round of the game, we need to check the rules based on the value of the round:

If the round is divisible by 3, player 2 will spend 3 coins.

If the round is not divisible by 3 but is divisible by 2, player 2 will spend 2 coins.

If the round is not divisible by 3 and not divisible by 2, player 2 will spend 1 coin.

So, the method getPlayer2Move should be defined as follows:

public

int getPlayer2Move(int round)

{

if (

round % 3 == 0) { return 3;

}

else if

(

round % 2 == 0

) {

return 2;

} else {

return 1;

} }

User Pil
by
3.3k points