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

Heads or Tails java program Using the Strategy and StrategyRandom class in the r

ID: 3678924 • Letter: H

Question

Heads or Tails java program

Using the Strategy and StrategyRandom class in the repository below

https://github.com/seccodingguy/CMSC325/tree/master/src/cmsc325gameconcepts

Create a game that prompts the user to choose heads or tails, flips a virtual coin, and then displays the results to the user. The game must continue until 100 flips have been completed. Save the results of the flip results in a format of your choosing.

Modify the code to include the StrategyProbability class, using the results saved from the StrategyRandom as the starting values for the setMoves() function. The game must continue until 100 flips have been completed. Save the results of the flip results in a format of your choosing and separate from the StrategyRandom results.

For both 2 and 3, generate statistics on the odds of getting the right guess as well as the number of heads and tails flipped, displayed, respectively, to the user as well as saved with the results.

The program does not have to use graphics of actual coins - this is optional.

The 100 flips can be generated manually, i.e. user pressing a button, or automatically.

Thanks,

Explanation / Answer

Can help you with this:


import java.util.Scanner;
public class Random
{
public static void main(String[] args)
{
try
{
StrategyRandom stratRandom = new StrategyRandom();
Scanner scanner = new Scanner(System.in);
int choice = 1;
int heads;
int tails;
int coinFlip = 0;
System.out.print("Enter your name: ");
stratRandom.name = scanner.nextLine();
System.out.println("Press 1 for Heads" + " Press 2 for Tails"+ " Press 0 to Exit");
choice = Integer.parseInt(scanner.nextLine());
while (choice != 0)
{
heads = 0;
tails = 0;
for (int i = 0; i < 100; i++)
{
coinFlip = stratRandom.nextMove();
if (coinFlip == 0)
{
heads++;
System.out.print("H,");
}
else
{
tails++;
System.out.print("T,");
}
}
if( choice == 1 )
{
if (heads > tails)
System.out.println(" You Won");
else if(tails > heads )
System.out.print(" You Lost");
}
else
{
if ( heads < tails )
System.out.println(" You Won");
else if( tails < heads )
System.out.print(" You Lost");
}
if( heads == tails )
System.out.println( "It is a tie!");
System.out.println(" Times head was flipped: " + heads);
System.out.println("Times tails was flipped: " + tails);
System.out.print(" Hello " + stratRandom.getName()+ ", Enter a number or 0 to exit: ");
choice = Integer.parseInt(scanner.nextLine());
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}

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