Question

In: Computer Science

Write the program to analyze whether a die is fair by counting how often the values...

Write the program to analyze whether a die is fair by counting how often the values 1, 2, ..., 6 appear. • The input is a sequence of die toss values. • The output is a table with the frequencies of each die value, as shown in the following figure.

in java

Solutions

Expert Solution

//TestCode.java
import java.util.Scanner;
public class TestCode {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Input a sequence of die toss values: ");
        String s = scanner.nextLine();
        String[] splits = s.split(" ");

        int counts[] = new int[6];
        int n;

        for(int i = 0;i<counts.length;i++){
            counts[i] = 0;
        }

        for(int i = 0;i<splits.length;i++){
            n = Integer.parseInt(splits[i]);
            counts[n-1]++;
        }

        System.out.println("Toss value\t\tCount");
        System.out.println("----------------------");
        for(int i = 0;i<counts.length;i++){
            System.out.println((i+1)+"\t\t\t\t"+counts[i]);
        }
    }
}


Related Solutions

Write the program to analyze whether a die is fair by counting how often the values...
Write the program to analyze whether a die is fair by counting how often the values 1, 2, ..., 6 appear. • The input is a sequence of die toss values. • The output is a table with the frequencies of each die value, as shown in the following figure. o
Write a program to simulate rolling a six-sided fair die. Allow the user to enter the...
Write a program to simulate rolling a six-sided fair die. Allow the user to enter the number of rolls. Your program should use rand() to get the result of die rolling. Compute the number of occurrences for each number roll. Calculate the percentage for each number roll. Out put the results in the following format. Use a do while loop to allow the user to repeat the process. Here is the sample run for your program: Please enter the number...
The experiment of rolling a fair six-sided die twice and looking at the values of the...
The experiment of rolling a fair six-sided die twice and looking at the values of the faces that are facing up, has the following sample space. For example, the result (1,2) implies that the face that is up from the first die shows the value 1 and the value of the face that is up from the second die is 2. sample space of tossing 2 die A pair of dice is thrown. Let X = the number of multiples...
(Expected values) Suppose you roll a fair die and your opponent flips a fair coin simultaneously....
(Expected values) Suppose you roll a fair die and your opponent flips a fair coin simultaneously. You win $4 whenever a Head appears and the number of dots on the top face of the dice is either one or six. For all other outcomes, you lose $1. (a) (2pts) How many possible outcomes are there? An outcome is the combined result of both coin-flipping and dice-rolling. (b) (3pts) What is your expected payoff? (c) (3pts) What is your opponent’s expected...
Jeff and Mark are trying to decide whether a die is fair. They roll it 100...
Jeff and Mark are trying to decide whether a die is fair. They roll it 100 times, with the results shown below: 19 ones, 13 twos, 15 threes, 21 fours, 18 fives, 14 sixes. Average ≈ 3.43, SD ≈ 1.76. Jeff wants to make a z-test, Mark wants to make a χ2 -test. Who is right? Explain briefly. Then, calculate the p-value of the respective test. Is the die fair?
1. The experiment of rolling a fair six-sided die twice and looking at the values of...
1. The experiment of rolling a fair six-sided die twice and looking at the values of the faces that are facing up, has the following sample space. For example, the result (1,2) implies that the face that is up from the first die shows the value 1 and the value of the face that is up from the second die is 2. (1,1)       (1,2)       (1,3)       (1,4)       (1,5)       (1,6) (2,1)       (2,2)       (2,3)       (2,4)       (2,5)       (2,6) (3,1)       (3,2)       (3,3)       (3,4)       (3,5)       (3,6)...
Consider the following experiment: Simultaneously toss a fair coin and, independently, roll a fair die. Write...
Consider the following experiment: Simultaneously toss a fair coin and, independently, roll a fair die. Write out the 12 outcomes that comprise the sample space for this experiment. Let X be a random variable that takes the value of 1 if the coin shows “heads” and the value of 0 if the coin shows “tails”. Let Y be a random variable that takes the value of the “up” face of the tossed die. And let Z = X + Y....
Write a C++ die roller program. We need you to write a program that will roll...
Write a C++ die roller program. We need you to write a program that will roll dice for them, but not just six-sided dice. Your program needs to be able to take an input in for form nDx or ndx where the d is the letter d or D. n may or not be present. If it is, it represents the number of dice. If not, assume it is a 1. x may or may not be present. If it...
Assume that you have a fair 6 sided die with values {1, 2, 3, 4, 5,...
Assume that you have a fair 6 sided die with values {1, 2, 3, 4, 5, 6} and a fair 12 sided die with values {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}. A discrete random variable is generated by rolling the two dice and adding the numerical results together. (a) Create a probability mass function that captures the probability of all possible values of this random variable. You may use R or draw the pmf...
In a Java program, how could I write a program that can assign values that would...
In a Java program, how could I write a program that can assign values that would make a rock paper scissors game work? I have a program that will generate a computer response of either rock, paper, or scissors but how can I compare a user input of "rock", "paper", or "scissors" so that we can declare either the user or the computer the winner.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT