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
"Rights and duties are two sides of the same coin." Explain with examples​
telo118 [61]

Answer:

Find the explanation below.

Explanation:

Rights are privileges that citizens or members of a community are entitled to by law. Duties are the responsibilities required of them. These two work together and are dependent on each other. Performing our duties help to safeguard our rights.

For example, the law specifies the right to life for people. This is an entitlement that should be respected by the individual and others around him. It is therefore the duty of the individual and others to respect this right to life and never compromise it in any way.

The law allows the right to free speech. It is also our duty to be patriotic and this would prevent compromising the right to free speech by saying unpatriotic things that can cause political tensions.

3 0
3 years ago
Technically a coding question utilizing python how would one calculate a square root
WITCHER [35]

Answer:

import math

math.sqrt( x )

Explanation:

The basic code that can be written to calculate the square root of a number is as follows

import math

math.sqrt( x )

5 0
3 years ago
Consider a class ClassName whose methods are listed below. What class is it?
Varvara68 [4.7K]

Answer:

An implementation of java.util.List interface

Explanation:

Given class consists of the following constructs:

  • Constructor
  • isEmpty,search, display
  • insert,remove

It supports inserting and removing an element at a specified index. It also supports search and display operations.

These are characteristics of an object which implements the java.util.List interface ( For example: ArrayList or user-defined customList ).

8 0
3 years ago
Whales thrive in the benthic zone because it is full of plankton.<br> Is it true or false
lorasvet [3.4K]

Answer:

true

Explanation:

4 0
3 years ago
A/an ____ file saves a workbook as a comma-delimited text file for use on another windows operating system??
aleksandrvk [35]

Answer:

The correct option is D

D) CVS

Explanation:

A CVS file saves a workbook as a comma-delimited text file for use on another windows operating system. It ensures that line breaks, tab characters and other characteristics are interpreted correctly.

A CVS file stands for Comma Separated Value file, which basically allows the data to be saved in tabular format. However they differ from other spreadsheet file types because you can only have a single sheet in a file. Moreover, you cannot save cell, column or row in it.

7 0
3 years ago
Other questions:
  • What is the difference between the Paste Special and Paste Link options?
    7·2 answers
  • A _______ acts as a security buffer between a corporation's private network and all external networks.
    7·1 answer
  • How can I lag my computer as if it had bad internet?
    15·1 answer
  • Consider a class called Rocket that has a private instance variable called Engine. You are writing a "getter" for the Engine. Us
    7·1 answer
  • IF YOU ARE COMPUTER MASTER TELL ME WHICH SOFTWARE IS USED IN CALLIGRAPHY
    6·2 answers
  • How do I make my own extension for chrome?
    7·1 answer
  • As the number of billboards for a firm's product increases from 100 to 500, its sales increase from $1,000 to $10,000. If this i
    13·1 answer
  • In Rizzati Corp, vice presidents in departments such as engineering, manufacturing, IT, and human resources report directly to t
    15·1 answer
  • 1. Choose a real or made up company, and describe at least three ways in which the company uses technology. (1-3 sentences. 3.0
    13·1 answer
  • Define and use in your program the following functions to make your code more modular: convert_str_to_numeric_list - takes an in
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!