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

Write a program that will print out statistics for eight coin tosses. CANNOT USE

ID: 640523 • Letter: W

Question

Write a program that will print out statistics for eight coin tosses. CANNOT USE BRANCHING (if-then statements, switch-case, etc.) The user will input either an H for heads or T for tails for the eight tosses. The program will then print out the total number of percentages of heads and tails. Use the incrimment operator (++) to increment the number of tosses as each coin toss is input.

SAMPLE OUTPUT

For each coin toss enter either 'h' for heads or 't' for tails:
First toss: h
Second toss: t
Third toss: t
Fourth toss: h
Fifth toss: t
Sixth toss: h
Seventh toss: t
Eighth toss: t

Number of Heads: 3
Number of Tails : 5
Percent Heads: 37.5%
Percent Tails: 62.5%

Explanation / Answer

import javax.swing.*; public class CoinToss { public static void main (String [] arg) { int NumberOfHead=0, NumberOfTail=0; double PercentageOfHead=0, PercentageOfTail=0; String HT= ""; HT= JOptionPane.showInputDialog("First toss:"); System.out.println("First toss: " + HT); NumberOfTail+=HT.charAt(0)/((int)('t')); HT = JOptionPane.showInputDialog("Second toss:" ); System.out.println("Second toss: "+ HT); NumberOfTail+=HT.charAt(0)/((int)('t')); HT = JOptionPane.showInputDialog("Third toss: " ); System.out.println("Third toss: " + HT); NumberOfTail+=HT.charAt(0)/((int)('t')); HT = JOptionPane.showInputDialog("Fourth toss: "); System.out.println("Fourth toss: "+ HT); NumberOfTail+=HT.charAt(0)/((int)('t')); HT = JOptionPane.showInputDialog("Fifth toss: "); System.out.println("Fifth toss: "+ HT); NumberOfTail+=HT.charAt(0)/((int)('t')); HT = JOptionPane.showInputDialog("Sixth toss: "); System.out.println("Sixth toss: "+ HT); NumberOfTail+=HT.charAt(0)/((int)('t')); HT = JOptionPane.showInputDialog("Seventh toss: "); System.out.println("Seventh toss: "+ HT); NumberOfTail+=HT.charAt(0)/((int)('t')); HT = JOptionPane.showInputDialog("Eighth toss: " ); System.out.println("Eighth toss: " + HT); //calculation NumberOfTail+=HT.charAt(0)/((int)('t')); NumberOfHead=8-NumberOfTail; PercentageOfHead=(double)NumberOfHead/8*100; PercentageOfTail=100- PercentageOfHead; //Output System.out.println("Number of head : "+NumberOfHead); System.out.println("Number of Tail : "+NumberOfTail); System.out.println("Percentage of head : "+PercentageOfHead); System.out.println("Percentage of Tail : "+PercentageOfTail); } }

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