answer.
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
natka813
2 months 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:
zubka84 [1K]2 months ago
3 0

Answer:

(1)

public int getPlayer2Move(int round) {

  int result = 0;

  //If the round number is divisible by 3

  if(round % 3 == 0) {

      result = 3;

  }

  //If round isn't divisible by 3 but is divisible by 2

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

      result = 2;

  }

  //If it's neither divisible by 3 nor 2

  else {

      result = 1;

  }

  return result;

}

(2)

public void playGame() {

 //Initializing coins for player 1

  int player1Coins = startingCoins;

 //Initializing coins for player 2

  int player2Coins = startingCoins;

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

      //If either player has less than 3 coins

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

          break;

      }

      //Coins spent by player 1

      int player1Spends = getPlayer1Move();

      //Coins spent by player 2

      int player2Spends = getPlayer2Move(round);

      //Calculating remaining coins for player 1

      player1Coins -= player1Spends;

      //Calculating remaining coins for player 2

      player2Coins -= player2Spends;

      //If both players spend the same amount

      if(player1Spends == player2Spends) {

          player2Coins += 1;

          continue;

      }

      //Calculating the absolute difference in coins spent

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

      //If the difference is 1

      if(difference == 1) {

          player2Coins += 1;

          continue;

      }

      //If the difference is 2

      if(difference == 2) {

          player1Coins += 2;

          continue;

      }

  }

 //At the end of the game

 //If both players have equal coins

  if(player1Coins == player2Coins) {

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

  }

  //If player 1 has more coins than player 2

  else if(player1Coins > player2Coins) {

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

  }

  //If player 2 has more coins than player 1

  else if(player1Coins < player2Coins) {

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

  }

}

You might be interested in
In cell e5, create a formula using the vlookup function to determine the dog type for teen anna morante based on the program cod
Natasha_Volkova [1026]
Hi! For utilizing the VLOOKUP function, you require the value to search for, the table’s range, and the specific column that has the return value. In your scenario, you provided both the range and the column; however, it’s unclear what value you wish to look up. For this explanation, let’s assume you want to search for the value in cell D5. Feel free to modify it according to your needs.

In syntax form, it will be:
=VLOOKUP(D5,G4:H7,2)
3 0
2 months ago
Read 2 more answers
An employee of a large corporation remotely logs into the company using the appropriate username and password. The employee is a
Natasha_Volkova [1026]

Respuesta: Te proporcioné 6 opciones de las cuales puedes elegir.

Integridad

Escalabilidad

Calidad de Servicio

Tolerancia a Fallos

Redes de Línea Eléctrica

Seguridad

6 0
2 months ago
Which type of testing is done when one of your existing functions stop working?
oksian1 [950]
The answer to the question is "alpha testing". Alpha testing aims to address issues like errors and debugging before software is launched. This testing is performed by developers when problems arise. In the software testing process, alpha testing occurs first, followed by beta testing. During alpha testing, developers check existing modules or functions that may have malfunctioned, ensuring any detected errors are addressed.
6 0
2 months ago
Need 2.5 Code Practice Answers
Natasha_Volkova [1026]

Answer:

import random

random.seed(1,10) # Note: seed takes one argument, so this line has an error

a = random.randint(1, 10)

b = random.randint(1, 10)

print("Calculate: " + str(a) + " X " + str(b) + "?")

ans = int(input("Your answer: "))

if ans == a * b:

print("Well done!")

else:

print("That's wrong!")

Explanation:

4 1
3 months ago
Read 2 more answers
Delete Prussia from country_capital. Sample output with input: 'Spain:Madrid,Togo:Lome,Prussia: Konigsberg' Prussia deleted? Yes
Amiraneli [1052]

Answer:

Explanation:

When removing items from a dictionary, always specify the key in quotation marks.

For example: del country_capital['Prussia']

Failing to place it in quotes will cause the interpreter to view Prussia as a variable, resulting in an error saying that Prussia is not defined.

Code:

user_input=input("") #taking input from user

entries=user_input.split(',')    

country_capital=dict(pair.split(':') for pair in entries) #creating the dictionary from user input

del country_capital['Prussia'] #removing Prussia; failure to include quotes results in an error

print('Prussia deleted?', end=' ')

if 'Prussia' in country_capital: #verifying the presence of Prussia in the dictionary

print('No.')

else:

print('Yes.')

print ('Spain deleted?', end=' ')    

if 'Spain' in country_capital: #checking if Spain is present in the dictionary

print('No.')

else:

print('Yes.')

print ('Togo deleted?', end=' ') #verifying the existence of Togo in country_capital

if 'Togo' in country_capital:

print('No.')

else:

print('Yes.')

Explanation:

3 0
3 months ago
Other questions:
  • In what areas is Leslie's underspending hurting her budget select all that apply
    5·1 answer
  • . Electricians will sometimes call ______ "disconnects" or a "disconnecting means."
    12·1 answer
  • Why computer is known as versatile and diligent device ?explain​
    14·1 answer
  • The video clip on driverless cars explained that brain signals from the individual wearing the headset are converted by computer
    13·2 answers
  • Any software or program that comes in many forms and is designed to disrupt the normal operation of a computer by allowing an un
    13·1 answer
  • When performing actions between your computer and one that is infected with a virus which of the following offers no risk becomi
    5·1 answer
  • A 1.17 g sample of an alkane hydrocarbon gas occupies a volume of 674 mL at 28°C and 741 mmHg. Alkanes are known to have the gen
    14·1 answer
  • Q2 - Square Everything (0.25 points) Write a function called square_all that takes an input called collection that you assume to
    7·1 answer
  • An ISP is granted the block 16.12.64.0/20. The ISP needs to allocate addresses for 8 organizations, each with 256 addresses. a.
    12·1 answer
  • Java Programming home &gt; 1.14: zylab training: Interleaved input/output Н zyBooks catalog Try submitting it for grading (click
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!