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
You would like to conduct a survey and ask your web page visitors to indicate the computer operating systems that they use. Each
Rudiy27

Answer:

<em>A. check box </em>

Explanation:

A check box, selection box, or tick box <em>is a small immersive box that the user can switch to demonstrate an affirmative or negative choice</em>.

It is often observed in applications and operating systems ' HTML input forms, dialog boxes, and GUIs.

A check mark appears inside the box when clicked to signify an affirmative (yes) option. The check mark will vanish when clicking again, suggesting a negative option (no).

6 0
3 years ago
4 types of system software
Elina [12.6K]
Operating systems.
Device drivers.
Middleware.
Utility software.
8 0
3 years ago
Read 2 more answers
If someone has the IP address 127.0.0.1 and tries to connect to the address 127.255.252.255, which are they attempting to connec
sertanlavr [38]
B is the answer i think
6 0
3 years ago
Indicate if the following statements are True or False. Statement Circle one Internet Service Providers (ISPs) are proprietary n
Artyom0805 [142]

Answer:

False

Explanation:

Proprietary networks are those that are privately and exclusively managed, controlled and even owned by some organizations.

Internet Service Providers (ISPs) are companies that provide internet access services to companies and consumer products. They allow devices to connect to the internet. They offer much more than just internet access. They also offer related services such as email access, web development and virtual hosting.

ISPs can be open source or proprietary. They could be owned by a community, a firm and even non-profit organizations.

5 0
3 years ago
Give 3 advantages of using shortcut key, especially in MS Office.
Darina [25.2K]

Answer:

Efficient and time-saving. Using shortcuts makes you more efficient at doing certain tasks on your computer. ...

Multi-tasking. Being a multi-tasker is sometimes required in life. ...

Health benefits.

4 0
3 years ago
Other questions:
  • Format Painter cannot be used to copy only character attributes. True or False
    12·1 answer
  • A type TW cable containing two No. 12 copper conductors has a maximum overcurrent protection of
    7·2 answers
  • What aspect does not provide context in a portrait?
    10·2 answers
  • Which of the following statements is true of intrapreneurs
    15·1 answer
  • Your supervisor has asked you to set up a RAID hard drive array in a tower system, which has a motherboard that uses the B360 ch
    10·1 answer
  • Super easy question but you have to think about it because it’s not that easy I’ll mark brainliest for first answer Explain the
    11·1 answer
  • How many bytes of information can be stored on a hard drive?
    7·1 answer
  • Is there a syntax error in the following code? bool hourlyWorker = true; if (hourlyWorker) cout &lt;&lt; "The employee is an hou
    12·1 answer
  • HELP PLEASE
    7·1 answer
  • ABC company have lots of computer running window 7. But they are not thinking to upgrade a higher version of window. One of the
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!