Question 1:
Write a Java program that computes the exact probability distribution for the sum of two dice. Run experiments to validate this calculation simulating N dice throws, keeping track of the frequencies of occurrence of each value when you compute the sum of two random integers between 1 and 6. How large does N have to be before your empirical results match the exact results to three decimal places?
Hi
Here is the java code to simulate the rolling of two dices and finding the probability of having the sum in the range of 2 to 12 inclusive.
We are doing the experiment 100000 times and printing the probabilities of the actual and expected.
________________________________________________________________________________________________/
import java.util.Random;
public class Dice {
public static void main(String[] args) {
int sum = 0;
int dice1 = 0;
int dice2 = 0;
int actual = 0;
int[] occurenceCount = new int[13];
int[] ways = {0, 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1};
for (int i = 0; i < 100000; i++) {
sum = 0;
dice1 = new Random().nextInt(6) + 1;
dice2 = new Random().nextInt(6) + 1;
sum = dice1 + dice2;
occurenceCount[sum]++;
}
for (int i = 0; i < 13; i++) actual += occurenceCount[i];
System.out.printf("%-4s %s %-11s %s%n", "Sum", "Total", "Expected",
"Actual");
for (int i = 2; i < 13; i++) {
System.out.printf("%-4d %-5d %-10.4f %2.4f%n", i, occurenceCount[i],
100.0 * ways[i] / 36, 100 * (double) occurenceCount[i] / actual);
}
}
}
____________________________________________________________________________________________
thank you !
Question 1: Write a Java program that computes the exact probability distribution for the sum of...
in java
Write an application that: 1. Prompts the user for a number of trials to perform (I will call this "N"). This operation should be type-safe for integers. 2. Simulates N trials of rolling two dice and finding the sum. 3. Uses an array to keep track of how many times each outcome has been rolled (you do not need to keep track of the actual rolls themselves). 4. Computes the percentage of the total number of rolls for...
Row and columns sum Create a java program that: Input: Receive as input in command line the sizes m and n of a two dimensional array Receive as input in command line the minValue and maxValue between which the random numbers will be generated for your two dimensional array Generate: Generate a two-dimensional with numbers between minValue and maxValue (inclusive) with the given size (m x n) Compute: Compute the sum for each row and store the results in a...
Exercise 1 Write a program that asks the user to enter the seed for a random number generator. Then the program uses this seed to roll a dice and hence generates two integers corresponding to the faces of each dice. If their sum is odd, the user has two tries to guess the sum. The program gives the user a hint after the first try. Otherwise, the user has three tries to guess the sum. Sample run 1: Enter the...
Write a script that works in vim: We are given a Java program RandomTest.java that generates specified number of random integers in the range [0...99]. The program prints FAIL if either 0 or 99 is generated (along with a count of how many times). Otherwise it prints PASS. The program takes the number of random integers to generate as a command line argument as shown below. Note that the given results each time is is run. [an@localhost ~] java Random...
Java question
Given an array of integer numbers, write a linear running time complexity program in Java to find the stability index in the given input array. For an array A consisting n integers elements, index i is a stability index in A itf ATO] + A[1] + +A[iI-1] Ali+1]+ Ali+2] +... + A[n-1]; where 0 <i< n-1 Similarly, 0 is an stability index if (A[1] A[2]A[n-1]) 0 and n-1 is an stability index if (A[0] A[1]+... A[n-21) 0 Example:...
Write a Java program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one of the following: +, -, *, /, or % representing the usual arithmetic operators (Each operation should be done on numbers negative(-) to positive(+), positive(+) to negative(-), negative(-) to negative(-), and positive(+)...
Use a java program that does the following:
. (10 points) Write a program as follows a. Prompt the user to input two positive integers: nl and n2 (nl should be less than n2) b. If the user enters the negative number(s), convert it/them to positive number(s) c. If nl is greater than n2, swap them. d. Use a while loop to output all the even numbers between nl and n2 e. Use a while loop to output the sum...
you can do it by hand
2 Distribution of sample mean 1, write a script to obtain the sample mean values with n = 4 for a total of 10000 experiments, where each sample is drawn normally from N(0,1). This results in 10000 sample mean values. (10pt) variance? (5pt) (5pt) 2. Consider the sample mean as a random variable X, what are its mean and 3. Does your observation from (a) match with your calculation from (b)?
1. Write a Java program to implement Counting Sort and write a driver to test it. Note: use random number generator to generate your input with n = 10, 50, and 100. Verify that the running time is O(n). 2. Write a Java program to implement Bucket Sort and write a driver to test it. Note: use random number generator to generate your input with n = 10, 50, and 100. Verify that the running time is O(n). 3. In...
Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...