1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lianna [129]
3 years ago
14

Assume that getPlayer2Move works as specified, regardless of what you wrote in part (a) . You must use getPlayer1Move and getPla

yer2Move appropriately to receive full credit. Complete method playGame below. /** Plays a simulated game between two players, as described in part (b). */ public void playGame()
Computers and Technology
1 answer:
kakasveta [241]3 years ago
3 0

Answer:

(1)

public int getPlayer2Move(int round)

{

  int result = 0;

 

  //If round is divided by 3

  if(round%3 == 0) {

      result= 3;

  }

  //if round is not divided by 3 and is divided by 2

  else if(round%3 != 0 && round%2 == 0) {

      result = 2;

  }

  //if round is not divided by 3 or 2

  else {

      result = 1;

  }

 

  return result;

}

(2)

public void playGame()

{

 

  //Initializing player 1 coins

  int player1Coins = startingCoins;

 

  //Initializing player 2 coins

  int player2Coins = startingCoins;

 

 

  for ( int round = 1 ; round <= maxRounds ; round++) {

     

      //if the player 1 or player 2 coins are less than 3

      if(player1Coins < 3 || player2Coins < 3) {

          break;

      }

     

      //The number of coins player 1 spends

      int player1Spends = getPlayer1Move();

     

      //The number of coins player 2 spends

      int player2Spends = getPlayer2Move(round);

     

      //Remaining coins of player 1

      player1Coins -= player1Spends;

     

      //Remaining coins of player 2

      player2Coins -= player2Spends;

     

      //If player 2 spends the same number of coins as player 2 spends

      if ( player1Spends == player2Spends) {

          player2Coins += 1;

          continue;

      }

     

      //positive difference between the number of coins spent by the two players

      int difference = Math.abs(player1Spends - player2Spends) ;

     

      //if difference is 1

      if( difference == 1) {

          player2Coins += 1;

          continue;

      }

     

      //If difference is 2

      if(difference == 2) {

          player1Coins += 2;

          continue;

      }

     

     

  }

 

  // At the end of the game

  //If player 1 coins is equal to player two coins

  if(player1Coins == player2Coins) {

      System.out.println("tie game");

  }

  //If player 1 coins are greater than player 2 coins

  else if(player1Coins > player2Coins) {

      System.out.println("player 1 wins");

  }

  //If player 2 coins is grater than player 2 coins

  else if(player1Coins < player2Coins) {

      System.out.println("player 2 wins");

  }

}

You might be interested in
Search..
djyliett [7]

Answer:

Denis Shikhalev, Renat Khabibulin, Ulrich Kemloh, Sergey Gudin

Pages 122-139

PDF

Event Monitoring System to Classify Unexpected Events for Production Planning

Andrés Boza, Faustino Alarcón, M. M. E. Alemany, Llanos Cuenca

Pages 140-154

PDF

Router Nodes Placement Using Artificial Immune Systems for Wireless Sensor Industrial Networks

Pedro Henrique Gouvêa Coelho, Jorge Luís Machado do Amaral, José Franco Machado do Amaral, Luciane Fernanda de Arruda Barreira, Adriano Valladão Barros

Pages 155-172

5 0
3 years ago
There are several vehicles in a parking lot. Some of them are motorcycles
GREYUIT [131]

Answer:

The answer is 34.

Explanation:

Look at the pic.

4 0
3 years ago
Read 2 more answers
What is one major difference between the roles of film directors and theater directors? A. A theater director is involved in sel
Umnica [9.8K]

Answer:

the answer is a cause I did this at my school and I learned about it so it A,

7 0
3 years ago
What is considered necessary to establish OSHA
irakobra [83]
OSHA (the Occupational Safety and Health Administration) is a part of the US Department of Labor that establishes, issues, and enforces national workplace safety regulatio…ns. These are designed to make job areas and practices safer for US workers.
4 0
3 years ago
What is the name of the function below?<br><br> function go(){<br> alert("hello everybody");<br> }
labwork [276]

Answer:

It’s Java script I think and it makes something say hello everybody

Explanation:

6 0
3 years ago
Other questions:
  • __________ involves analyzing a large amount of data to extract knowledge and insight
    13·1 answer
  • Computer hardware had been designed to run a single operating system and a single app, leaving computers vastly underutilized. o
    15·1 answer
  • Jason works as an accountant in a department store. He needs to keep a daily record of all the invoices issued by the store. Whi
    13·2 answers
  • So when i try to click on an assignment to answer it the ask a question thing pops up and i can't exit out of it. I've tried rel
    10·2 answers
  • Which image shows organic shapes? <br> A. image 1 <br> B. image 2 <br> C. image 3 <br> D. image 4
    14·2 answers
  • 1. A tachometer measures:
    8·1 answer
  • Implement RandMultipByVal function, which gets one integervariable as its argument
    12·1 answer
  • What in the LAN for a small office, some user devices connect to the LAN using a cable, while others connect using wireless tech
    14·1 answer
  • Can i edit my name on this app?
    7·1 answer
  • Ken has discovered that a vice president of his company has been using his computer to send data about a new product to a compet
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!