Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose two teams are playing each other in a best-of-seven playoff (the two tea

ID: 3532420 • Letter: S

Question

Suppose two teams are playing each other in a best-of-seven playoff (the two teams play each other until one team wins four games). Suppose one team is more likely to win each game (say 51%). What are the chances that the better team will win the playoff?

We can solve this problem mathematically (the answer is about 52.2%), but simulations are often needed for more complicated problems involving uncertainty. Multiple simulations can give us an idea of what the chances are. For example, if we simulate a playoff 2500 times, our results will probably be within 1% of the correct answer (oversimplifying statistics here).

How can you simulate a 51% chance? The standard technique is to generate pseudorandom numbers, a sequence of numbers that appears to be random, but is actually generated by a program. The Random class provides pseudorandom numbers in Java. Here is an example.


Write one method to play a single game. This method should have two parameters: the percent chance that Team 1 will win the game, and a Random object. This method should only generate one random number. This method should return one value if Team 1 wins and a different value if Team 1 loses. In your final submission, this method should not print anything (comment out any print statements).

Write another method to simulate a playoff, that is, to play games until one team wins four games. This method must use a while loop for flow of control. This method should have two parameters: the percent chance that Team 1 will win the game, and a Random object. This method should return different values depending on which team wins. In your final submission, this method should not print anything (comment out any print statements).

Write a third method to keep doing playoffs until one team has won 10 more playoffs than the other team. This method must use a while loop for flow of control. This method should have two parameters: the percent chance that Team 1 will win the game, and a Random object. This method should print a 1 every time team 1 wins, and print a 2 every time team 2 wins; this should all be on one line. This method should also print the final results.

The main method should ask the user for the percent chance that team 1 will a game. It should ensure that the user enters an integer between 0 and 100. This method must use a while loop to ensure that a valid value has been entered. After obtaining a valid value, the main method should construct a Random object. Finally, the main method should pass the two values (the percent chance and the Random object) to the third method.

Explanation / Answer

Fully functional code


if(team1wincount-team2wincount==10)

{

return;

}

if(team2wincount-team1wincount==10)

{

return;

}

int num1 = rand.nextInt(100);

if (num1 < percent)

{

System.out.println("1");

team1wincount=team1wincount+1;

}

else

{

System.out.println("2");

team2wincount=team2wincount+1;

}

int num2 = rand.nextInt(100);

if (num2 < percent)

{

System.out.println("2");

team2wincount=team2wincount+1;

}

else

{

System.out.println("1");

team1wincount=team1wincount+1;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote