This is due in 2 days its supposed to be simple but i just cant get it.

Write a program that will print out statistics for a user-specified number of coin tosses. First the user should be asked about the total number of coin tosses possible. For this project, the total number of coin tosses will be restricted to three choices (4, 6, and 8). If an incorrect choice is entered, display an error message and exit. If a correct choice is entered, the user will input either an ‘h’ for heads or a ‘t’ for tails for the number of user-specified number of tosses. The program will then print out the total number and percentages of heads and tails. Use the increment operator to count each ‘h’ and ‘t’ that is input. For example, a possible sample dialog might be

Please enter the total number of coin tosses (You have a choice of 4, 6, or 8 total number of coin tosses): 8
For each coin toss enter either ‘h’ for heads or ‘t’ for tails.
Enter toss #1 output: h
Enter toss #2 output: t
Enter toss #3 output: t
Enter toss #4 output: h
Enter toss #5 output: t
Enter toss #6 output: h
Enter toss #7 output: t
Enter toss #8 output: t

Number of tails: 5
Percent tails: 62.5

If anyone knows how to create this it would be greatly appreciated

## All 7 Replies

i WILL DONATE A DECENT AMOUNT OF MONEY I CANNOT FAIL THIS CLASS... BUT I AM LOST... PLEASE HELP

THANK YOU
jUSTIN

Edit: Deleted taunt

When you get the number of tosses write if statements checking the validity of the information.

You must have variables where you count the successes and the failures

Then use a for-loop to print the:

"Enter toss #"+i+ "output: "

followed by the command for reading from the console.
Once you read the 'h' or 't', call a method that randomly calculates a coin toss. Then compare the value calculated with the one entered and increment one of the above variables if it was successful or not.
Then continue with the loop the same code,

At the end print the results.

The Math.random() generates a random number between 0 and 1. Use this to get a random coin-toss (if it is 0 - 0.5 the 'h' or if it is 0.5-1.0 't')

``````BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));

pseudocode

``````N = get number of tosses

for (i=1 to N) {
print: Enter toss #i output:
get toss from console
calculate random toss
compare them
update score variables
}
print the results``````

This is what I got so far and I am really stuck dont know where to go ... this is a beginners class so it has to be simple didnt learn much so far.
This is what I got.........Using netbeans.... dont know where else to go to get outputs like this:::

``````Please enter the total number of coin tosses (You have a choice of 4, 6, or 8 total number of coin tosses): 8
For each coin toss enter either ‘h’ for heads or ‘t’ for tails.
Enter toss #1 output: h
Enter toss #2 output: t
Enter toss #3 output: t
Enter toss #4 output: h
Enter toss #5 output: t
Enter toss #6 output: h
Enter toss #7 output: t
Enter toss #8 output: t

Number of tails: 5
Percent tails: 62.5
``````

Code:

``````/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package cointoss;

import java.util.Scanner;

//This import will allow the keyboard to be active.//

public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

PercentTails, Output ;

System.out.println("Please enter the total number of coin tosses" +
"(You have a choice of 4, 6, or 8 total number of coin tosses): " );

System.out.println("For each coin toss enter H ot T");

Scanner board = new Scanner(System.in);

Output = board.nextInt();

}

}
``````

This is what I got so far and I am really stuck dont know where to go ... this is a beginners class so it has to be simple didnt learn much so far.
This is what I got.........Using netbeans.... dont know where else to go to get outputs like this:::

Please enter the total number of coin tosses (You have a choice of 4, 6, or 8 total number of coin tosses): 8
For each coin toss enter either ‘h’ for heads or ‘t’ for tails.
Enter toss #1 output: h
Enter toss #2 output: t
Enter toss #3 output: t
Enter toss #4 output: h
Enter toss #5 output: t
Enter toss #6 output: h
Enter toss #7 output: t
Enter toss #8 output: t

Number of tails: 5
Percent tails: 62.5
_______________________________________________________________

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package cointoss;

import java.util.Scanner;

//This import will allow the keyboard to be active.//

public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

PercentTails, Output ;

System.out.println("Please enter the total number of coin tosses" +
"(You have a choice of 4, 6, or 8 total number of coin tosses): " );

System.out.println("For each coin toss enter H ot T");

Scanner board = new Scanner(System.in);

Output = board.nextInt();

}

}

I see no for-loop and I see nowhere where you read in how many tosses the user wants, unless it's this line:

``Output = board.nextInt();``

If it is, rename Output because it is a bad variable name. Name it `numTosses` or something.

You'll need a loop:

``````for (int i = 0; i < numTosses; i++)
{
Look at javaAddict's post and try to implement it. He's using `N` for `numTosses` , which is fine, but `Output` is a bad variable name for reading input.