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
1 month 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 [945]1 month 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
Use the following data definitions data myBytes BYTE 10h,20h,30h,40h myWords WORD 3 DUP(?),2000h myString BYTE "ABCDE" What will
Natasha_Volkova [897]

Answer:

Given Data:

myBytes BYTE 10h, 20h, 30h, 40h

myWords WORD 3 DUP(?), 2000h

myString BYTE "ABCDE"

From the supplied information, we can derive that:

(a).     a. EAX = 1

         b. EAX = 4

         c. EAX = 4

         d. EAX = 2

         e. EAX = 4

         f. EAX = 8

         g. EAX = 5

8 0
18 days ago
The Domain Name System (DNS) provides an easy way to remember addresses. Without DNS, how many octets for an Internet Protocol (
Harlamova29_29 [932]

Response:Four

Clarification:

The Domain Name System (DNS) serves as a naming framework, linking the names individuals use to find websites to the corresponding IP addresses utilized by computers to locate those websites. This system interacts with either the Internet or a private network.

An IP address, represented as a 32-bit binary number, is typically presented in a standard format as 4 octets in decimal notation for easier human comprehension.

6 0
14 days ago
A method countDigits(int num) of class Digits returns the remainder when the input argument num(num &gt; 0) is divided by the nu
ivann1987 [930]

Answer:

#include <iostream>

using namespace std;

class Digits

{

   public:

   int num;

   int read()       //method to read num from user

   {

       cout<<"Enter number(>0)\n";

       cin>>num;

       return num;

   }

   int digit_count(int num)  //method to count number of digits of num

   {

       int count=0;

       while(num>0)    //loop till num>0

       {

           num/=10;

           count++;   //counter which counts number of digits

       }

       return count;

   }

   int countDigits(int num)   //method to return remainder

   {

       int c=digit_count(num); //calls method inside method

       return num%c;  

   }

};

int main()

{

   Digits d;    //object of class Digits is created

   int number=d.read();   //num is read from user

   cout<<"\nRemainder is: "<<d.countDigits(number);  //used to find remainder

   return 0;

}

Output:

Enter number(>0)

343

Remainder is: 1

Explanation:

The program has a logical error that needs rectification. A correctly structured program calculates the remainder when a number is divided by the count of its digits. A class named Digits is created, consisting of the public variable 'num' and methods for reading input, counting digits, and calculating the remainder.

  • read() - This function asks the user to enter the value for 'num' and returns it.
  • digit_count() - This function accepts an integer and counts how many digits it has, incrementing a counter until 'num' is less than or equal to 0. It ultimately returns the digit count.
  • countDigits() - This function takes an integer and delivers the remainder from dividing that number by its digit count. The digit count is computed using the 'digit_count()' method.

Finally, in the main function, a Digits object is instantiated, and its methods are utilized to produce an output.

7 0
1 month ago
The function below takes a single string parameter: sentence. Complete the function to return a list of strings that are in the
Rzqust [894]

Response:

#section 1

def listofWordswitha(text):

   ''' This function outputs all words from a string that include the letter 'a' '''

   tex = text.split()

   new = []

#section 2

   for word in tex:

       for char in word:

           if char == 'a':

               new.append(word)

               

               break

   return new

Clarification:

#section 1

First, you need to establish your function and provide an argument representing the string that will be utilized.

It's beneficial to include a docstring that describes the function's purpose, which I've added.

Then, use the split method to break the string into a list. In conclusion, you create a list to store all the words that contain 'a'.

#section 2

The terminology chosen is specific to facilitate understanding.

FOR EVERY WORD inside the list and FOR EACH LETTER in the WORD.

IF a LETTER 'a' is found in the word, ADD that WORD to the NEW LIST.

The append function serves to incorporate new entries into the list.

A break statement is employed to avoid redundancy since some words might have multiple instances of 'a'. Thus, upon encountering a word containing 'a', it appends it and shifts to the next word.

Ultimately, the new list is returned.

I will utilize your inquiry to validate the code and provide the results for you.

4 0
1 month ago
Provide an example by creating a short story or explanation of an instance where availability would be broken.
Amiraneli [921]

Explanation:

Personal Insurance

Understanding workplace confidentiality: Key points

In professions where you advise clients or patients, safeguarding private and sensitive information is essential. But are you knowledgeable about what constitutes a confidentiality breach and how to handle it if it happens?

This passage provides insights into protecting confidential data and identifying breaches in various jobs, emphasizing the significance of confidentiality at work.

What does a breach of confidentiality entail?

Essentially, a breach occurs when information is shared with someone without the explicit consent of its owner. This refers to the failure to respect an individual's privacy or the trust they placed in you while sharing their information.

Why is maintaining confidentiality critical?

Safeguarding confidential information is crucial for those who access or handle such data at work. If confidentiality is compromised, it can jeopardize your professional reputation and relationships with current and future clients, which may lead to termination of contracts or legal consequences.

Therapist/patient confidentiality

Confidentiality for patients is especially vital for therapists and counselors. It plays an essential role in establishing proper boundaries, fostering a trusting therapeutic relationship.

Here are some examples of unintentional breaches of therapist/patient confidentiality:

Disclosing confidential client information to friends or family

Discussing confidential details in public spaces where others can overhear

Leaving computers with confidential information accessible to others

Continuing treatment for a client with known conflicts of interest (e.g., if they are acquainted with family or friends)

When individuals give permission to share information but without clarity, it may lead to misunderstandings and potential breaches (e.g., a patient may consent to share details with a teacher but not with their doctor).

7 0
1 month ago
Other questions:
  • When using the Python shell and code block, what triggers the interpreter to begin evaluating a block of code
    14·1 answer
  • A have a string, called "joshs_diary", that is huge (there was a lot of drama in middle school). But I don't want every one to k
    5·1 answer
  • Which is among the earliest formats of audio used in video games? A. MP3 B. wave table synthesis C. pulse code modulation D. MOD
    7·2 answers
  • 1. Orthographic Drawings are used to express ideas that are more complicated. Explain the purpose of the different views and the
    7·1 answer
  • You work for a car rental agency and want to determine what characteristics are shared among your most loyal customers. To do th
    10·1 answer
  • Debug the program so it prints the factorial of a positive integer entered by the user. This is calculated by multiplying all th
    9·1 answer
  • If a cell reference is c6, this cell is in the sixth column and the third row. true or false
    11·2 answers
  • Given main(), define the Team class (in file Team.java). For class method getWinPercentage(), the formula is:teamWins / (teamWin
    15·1 answer
  • Danielle, a help desk technician, receives a call from a client. In a panic, he explains that he was using the Internet to resea
    9·1 answer
  • Sean is white hat hacker, who is demonstrating a network level session hijack attacks and as part of it, he has injected malicio
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!