public class HeadsAndTails
{
public static void main(String[] args)
{
System.out.println("For each coin toss enter either ‘h’ for heads or ‘t’ for tails. ");
String toss1, toss2, toss3, toss4, toss5, toss6, toss7, toss8;
int heads, tails;
double percentHeads, percentTails;
System.out.println("First toss:");toss1 = SavitchIn.readLine(); //gets toss letter from user input
System.out.println("Second toss:"); toss2 = SavitchIn.readLine();//gets toss letter from user input
System.out.println( "Third toss:"); toss3 = SavitchIn.readLine();//gets toss letter from user input
System.out.println("Fourth toss:"); toss4 = SavitchIn.readLine();//gets toss letter from user input
System.out.println( "Fifth toss:"); toss5 = SavitchIn.readLine();//gets toss letter from user input
System.out.println("Sixth toss:"); toss6 = SavitchIn.readLine();//gets toss letter from user input
System.out.println( "Seventh toss:"); toss7 = SavitchIn.readLine();//gets toss letter from user input
System.out.println( "Eighth toss:"); toss8 = SavitchIn.readLine();//gets toss letter from user input
System.out.println("First Toss: " + toss1); //states what the user inputed
System.out.println("Second Toss: " + toss2);//states what the user inputed
System.out.println("Third Toss: " + toss3);//states what the user inputed
System.out.println("Fourth Toss: " + toss4);//states what the user inputed
System.out.println("Fifth Toss: " + toss5);//states what the user inputed
System.out.println("Sixth Toss: " + toss6);//states what the user inputed
System.out.println("Seventh Toss: " + toss7);//states what the user inputed
System.out.println("Eighth Toss: " + toss8);//states what the user inputed
heads = ;//unsure of how to count frequence. HELP ON THIS PART
tails = ;//unsure of how to count frequencies. HELP ON THIS PART!
percentHeads = ((double)heads / 8) * 100; //gets percentage of heads
percentTails = ((double)tails / 8) * 100; //gets percentage of tails
System.out.println("Number of heads " + heads);
System.out.println("Number of tails " + tails);
System.out.println("Percent heads: " + percentHeads);
System.out.println("Percent tails: " + percentTails);
System.out.println("Press any key to exit program.");
String junk;
junk = SavitchIn.readLine();
}
}
My assignment:
The user inputs either an 'h' for heads or 't' for tails for eight tosses,
then the program will print out the total number and percentages of head and tails. I am supposed to use an called increment operator to count, but I looked online everywhere and couldn't find out how to use it. I think I am doing this right, but I am not sure. We are supposed to use SavitchIn.java if you are wondering.