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
Write the half function. A function call and the functionprototype
EastWind [94]

Answer:

C code for half()

#include<stdio.h>

void half(float *pv);

int main()

{

float value=5.0;  //value is initialized  

printf ("Value before half: %4.1f\n", value); // Prints 5.0

half(&value);  // the function call takes the address of the variable.

printf("Value after half: %4.1f\n", value); // Prints 2.5

}

void half(float *pv) //In function definition pointer pv will hold the address of variable passed.

{

*pv=*pv/2;  //pointer value is accessed through * operator.

}

  • This method is called call-by-reference method.
  • Here when we call a function, we pass the address of the variable instead of passing the value of the variable.
  • The address of “value” is passed from the “half” function within main(), then in called “half” function we store the address in float pointer ‘pv.’ Now inside the half(),  we can manipulate the value pointed by pointer ‘pv’. That will reflect in the main().
  • Inside half() we write *pv=*pv/2, which means the value of variable pointed by ‘pv’ will be the half of its value, so after returning from half function value of variable “value” inside main will be 2.5.

Output:

Output is given as image.

3 0
3 years ago
What is the Digital Living Network Alliance ?
Sedaia [141]

The digital living alliance network is a set of guidelines to share digital media among wired and wireless multimedia devices.

<h3>What is the digital living alliance network?</h3>

The Digital Living Network Alliance is a trade association that establishes rules and practices for home network equipment, incorporating computers, smartphones, etc.

It is a set of guidelines to share digital media among wired and wireless multimedia devices.

Learn more about digital on:

brainly.com/question/23749502

#SPJ12

8 0
2 years ago
Read 2 more answers
When keying, keep fingers curved and upright over the home keys.<br> False<br> True
Dmitry [639]

Answer:

This is true.

Explanation:

I think everyone was taught to to type correctly sometime in school or at home. It helps you proficiently type. But most people don't use the Home Room Key Technique. Most use the "Chicken peck"

3 0
3 years ago
How many terabytes is a 128 gigabyte SD memory card
Maksim231197 [3]

Answer:

this would be .128 terabytes

Explanation:

This would be since for a whole terabyte you need 1000 gigabytes every 1000 gigabytes is a terabyte for example let’s say you have 5250 gigabytes you would have 5.250 terabytes that simple hope this helped!

4 0
2 years ago
Read 2 more answers
While a computer is running the operating system remains in memory. true or false?
MrMuchimi
While a computer is running the operating system remains in memory is true.
8 0
3 years ago
Other questions:
  • It is better to know the main components of all computer programming languages
    9·1 answer
  • Match the element of a presentation program to its description
    11·1 answer
  • The sum of all the minterms of a boolean function of n variables is equal to 1.
    7·1 answer
  • How to stop getting emails from colleges?
    9·1 answer
  • Instructions
    12·1 answer
  • Consider an application that transmits data at a steady rate (for example, the sender generates an N-bit unit of data every k ti
    8·1 answer
  • To access your gradebook you click on the __________.
    6·2 answers
  • A technician wants to limit access to a group of folders and is using Group Policy to prevent the users in the sales department
    9·1 answer
  • The average number of entities completed per unit time -- the output rate -- from a process is called ____.
    9·1 answer
  • Kevin would like to ensure that his software runs on a platform that is able to expand and contract as needs change. Which one o
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!