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

Heads or Tails java program https://github.com/seccodingguy/CMSC325/tree/master/

ID: 3678711 • Letter: H

Question

Heads or Tails java program

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

Using the Strategy and StrategyRandom class, 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

import java.util.Random;
import java.util;

class StrategyRandom
{
   public int randm()  
   {
       Random r= new Random();
       int a=r.nextInt(1);
       return a;
   }
}

class Strategy extends StrategyRamdom
{
   public static void result()
   {
       int a=randm();
       String ans1;
       Scanner scan=new Scanner(System.in);      
       System.out.println("Enter your guess");
       String ans=scan.nextLine();

       if(a==0)
           ans1="Head";
       else  
           ans1="Tail";

       if(ans.equals(ans1))
           System.out.println("U win");
       else
           System.out.println("U lost");

   }

   public static void main(String args[])
   {
       int i;

       for(i=0;i<100;i++)
       {
           result();
       }
   }
}
  
      

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