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
lianna [129]
1 year 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]1 year 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
2.4: Star Pattern Write a program that displays the following pattern: * *** ***** ******* ***** *** * Output. Seven lines of ou
adelina 88 [10]

Answer:

// here is code in java.

public class NAMES

{

// main method

public static void main(String[] args)

{

int n=4;

// print the upper half

for(int a=1;a<=n;a++)

{

for(int b=1;b<=n-a;b++)

{

// print the spaces

System.out.print(" ");

}

// print the * of upper half

for(int x=1;x<=a*2-1;x++)

{

// print the *

System.out.print("*");

}

// print newline

System.out.println();

}

// print the lower half

for(int y=n-1;y>0;y--)

{

for(int z=1;z<=n-y;z++)

{

// print the spaces

System.out.print(" ");

}

for(int m=1;m<=y*2-1;m++)

{

// print the *

System.out.print("*");

}

// print newline

System.out.println();

}

}

}

Explanation:

Declare a variable "n" and initialize it with 4. First print the spaces (" ") of the upper half with the help of nested for loop.Then print the "*" of the upper half with for loop. Similarly print the lower half in revers order. This will print the required shape.

Output:

  *

 ***

*****

*******

*****

 ***

  *

5 0
2 years ago
Haley's employer has asked her to review tens of thousands of social media posts about their company's products and compile this
ArbitrLikvidat [17]

Answer: Variety

Explanation:

According to the given question, Haley is dealing with the variety of the organization products posts on the social media networking as Haley's employer wants to comping all the data or information related to the products into the database system.

  • The database is one of the type of management system that manages all the database that are shared by the customers or users.
  • The main important function of the database is that it organize the data more accurately and properly in the system.
  • The database management system (DBMS) handle all the data in the system more effectively from the variety of the users.

Therefore, Variety is the correct answer.

7 0
1 year ago
Jeffrey works with a huge database of spreadsheet records each day. To organize and identify these spreadsheets, he wants to ass
mariarad [96]

Answer:

A. Document Properties

B. Permission

C. Document Options

D. File Details

The answer to this question is "File Details " . This will help Jeffrey works efficiently with a huge database of spreadsheet records each day. He can assign names to these File Details which represents each spreadsheet records. This will help his report more organized and easy to identity.

8 0
1 year ago
Write a second convertToInches() with two double parameters, numFeet and numInches, that returns the total number of inches. Ex:
mixer [17]

Answer:

   public static double convertToInches(double numFeet, double numInches){

       return (numFeet*12)+numInches;

   }

Explanation:

This technique of having more than one method/function having the same name but with different parameter list is called method overloading. When the method is called, the compiler differentiates between them by the supplied parameters. The complete program is given below

public class FunctionOverloadToInches {

   public static void main(String[] args) {

       double totInches = 0.0;

       totInches = convertToInches(4.0, 6.0);

       System.out.println("4.0, 6.0 yields " + totInches);

       totInches = convertToInches(5.9);

       System.out.println("5.9 yields " + totInches);

       return;

   }

   public static double convertToInches(double numFeet)

       {

           return numFeet * 12.0;

       }

       /* Your solution goes here */

   public static double convertToInches(double numFeet, double numInches){

       return (numFeet*12)+numInches;

   }

}

5 0
1 year ago
__________ filtering requires that the filtering rules governing how the firewall decides which packets are allowed and which ar
DIA [1.3K]

Answer:

Static

Explanation:

A computer or system administrator who want packets to be filter have to set or configured a filtering rules which will enable and allow the firewall to decide on which of the packets that will be allowed to function and the packets that will be denied not to function to be developed and as well installed on the firewall have to make use of what is called STATIC FILTERING reason been that STATIC FILTERING make it of necessary that the filtering rules should be developed and installed with the firewall.

6 0
1 year ago
Other questions:
  • Jacob wants to be a Steamfitter. He just finished his associate’s degree. Which best describes what he should do next?
    10·2 answers
  • GJAUDRO: A member of a team. Question 2 with 1 blankARBCUE: Activity that is practiced under the water. Question 3 with 1 blankE
    8·1 answer
  • You're the sole IT employee at your company, and you don't know how many users or computers are in your organization. Uh oh! Wha
    8·1 answer
  • Given an integer variable strawsOnCamel, write a statement that uses the auto-increment operator to increase the value of that v
    12·1 answer
  • A contact list is a place where you can store a specific contact with other associated information such as a phone number, email
    9·1 answer
  • A user complains that her computer is performing slowly. She tells you the problem started about a week ago when new database so
    15·1 answer
  • Program MATH_SCORES: Your math instructor gives three tests worth 50 points each. You can drop one of the test scores. The final
    7·1 answer
  • Your employer, yPlum Corporation is manufacturing two types of products: Mirabelle smartphone, and Blackamber laptop. The compan
    14·1 answer
  • If Maya wants to access a view that would control multiple slides within a presentation, which view should she utilize? Master v
    9·1 answer
  • Checkpoint 10.43 Write an interface named Nameable that specifies the following methods: _______{ public void setName(String n)
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!