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
Since the rules cannot address all circumstances, the Code includes a conceptual framework approach for members to use to evalua
Veseljchak [2.6K]

Answer:

more than one safeguard may be necessary.

Explanation:

The conceptual framework can be used to developed as well as construct through a process of the qualitative analysis. The approach includes the in the frameworks for identifying and evaluating the threats to compliance with the rules.

But since the rules formed cannot always address all the circumstances, the Code includes to evaluate the threats to the compliance of more than one safeguards that are necessary.

8 0
2 years ago
which of the following indicates that the loop should stop when the value in the quantity variable is less than the number 50​
yan [13]

Answer:

while (quantity >= 50)

Explanation:

Required

Stop when quantity is less than 50

To do this, we make use of a while statement and the syntax is:

while (condition){ }

If the loop should stop when quantity is less than 50; then it means the loop would continue when quantity is greater or equal to 50

So, we have:

while (quantity >= 50)

6 0
2 years ago
You want to equip yourself with FRUs for a laptop. What would you take with you? (Choose two)A. RAMB. SD card readerC. Video car
zloy xaker [14]

Answer:

RAM and Hard Drive

Explanation:

An FRU is also called a Field-repleacable Unit and is usually an assembly that is easily removed from an electronic equipment, laptop or just a computer and replaced so that one does not have to take the entire system for repairs. When trying to equip yourself with this unit of a laptop, you must take your Random Access Memory and your hard drive as they contain the whole information on the laptop.

4 0
2 years ago
What are the advantages and disadvantages of the simulated link strategy?
amid [387]

Answer:

The advantage of the simulated link strategy are:

  • It is easily able to provide the practical feedback to the customers and users while designing the whole system. It also determine the efficiency and the correctness of the design in the stimulated link strategy.
  • In the stimulated link strategy, the sharing and delivering of the data and information is done efficiently without any occurrence of error and interrupt. It is also high flexible technique.

The disadvantage of the simulated link strategy are:

  •   The simulated link strategy is flexible but it is not standardization and also it required more good concept.
  •  This technique is expensive and it is not readily available as it always require validation process.

3 0
3 years ago
How do you suppose a request travels from one computer to another? How does the request know where to go?
Luden [163]
It can request a signal then transfer certain data points and provide the request. The request knows where to go using certain lines in the data.
4 0
2 years ago
Other questions:
  • Two electronics technicians are looking at the testing instrument in the figure above. Technician A says that this instrument is
    7·1 answer
  • PLEASE HELP!!!!! MUCH OBLIGED!!!!
    15·1 answer
  • Can somebody help me?
    11·1 answer
  • What does it mean to say that two variables are negatively correlated?
    6·1 answer
  • Why is it a good idea to leave an interview being courteous and polite?
    10·1 answer
  • Which of the following is not an Operating System? Select one:
    13·1 answer
  • How does an individual's access to a wide range of online services affects their ability to operate safely in the digital world.
    5·1 answer
  • Code written by computer programmers is translated to binary code, so computers can understand the instructions. True or False
    7·1 answer
  • What are the defenses to protect against these attacks?
    13·1 answer
  • Să se determine valoarea sumei: l+2+3+…+n pentru un n număr natural citit de la tastatură. Sa se scrie un algoritm care calculea
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!