Question

In: Computer Science

Please fllll this out thank you /** * * Creates a six-sided die and rolls it...

Please fllll this out thank you

/**
*


* Creates a six-sided die and rolls it 20 times. It outputs the face values and also
* the number of times the die lands on 6.
*
* Creates 2 eight-sided dice and rolls the pair 10 times. It prints out a sequence
* of pairs representing the face values as well as the number of doubles.
*
* Allows the user to repeat the above steps as often as (s)he wishes.
*
* @author (put your name here!!!)
* @version (3-20-19)
*/
import java.util.*;
public class TestDie
{
public static void main (String [] args)
{
Scanner keyIn = new Scanner(System.in);

// display output heading
System.out.println ("Programmer: put your name here!!");
System.out.println ("Course: COSC 111, Winter '19");
System.out.println ("Lab: Exam 2, part 2");
System.out.println ("Due date: 3-20-19\n");


// create a six-sided die
// create a Die object and then call the method setSides to set the number of sides to 6


// roll the die 20 times, output the face value of each roll (4 per line), and the
// number of times the die lands on 6.
// set up a loop that iterates exactly 20 times, and each time through the loop do the following:
// roll the die by calling the method 'roll'; output the face value of the die; check the face
// value to keep track of 6s, and check to see if you have printed 4 numbers already, if yes,
// then advance to the next line.

System.out.println("Rolling a 6-sided die 20 times:" );

// create two eight-sided dice
// create two 'Die' objects and then use the method 'setSides' with each object to set its number of sides to 8

System.out.println("\nRolling a pair of 8-sided dice 10 times:");

// throw a pair of eight-sided dice 10 times, output the face values of each throw as a pair
// and also the number of doubles (both dice land on the same face value)
// set up a loop that iterates exactly 10 times, and each time through the loop do the following:
// roll both die by calling the method 'roll' twice; print out their face values as a pair;
// and check to see if both face values are the same, if yes, keep track of it.

// add a do-while loop to repeat the above code as often as the user wishes

}

}

Solutions

Expert Solution

Note:Dont forget to put your name in first print statement

code

TestDie:

import java.util.*;
public class TestDie{
  
   public static void main (String [] args){
  
       Scanner keyIn = new Scanner(System.in);

// display output heading
       System.out.println ("Programmer: put your name here!!");
       System.out.println ("Course: COSC 111, Winter '19");
       System.out.println ("Lab: Exam 2, part 2");
       System.out.println ("Due date: 3-20-19\n");
       do {
       Die die=new Die();
       die.setSides(6);
       int sixCount=0;
       int c=0;
       System.out.println("Rolling a 6-sided die 20 times:" );
       for(int i=0;i<20;i++) {
           int j=die.roll();
           if(j==6)
               sixCount++;
           if(c%4==0)
           System.out.println();
           c++;
           System.out.print(j+"\t");
       }
       System.out.println();
       System.out.println("Number of times six rolled is "+sixCount);
       Die eigdie = new Die();
       eigdie.setSides(8);
       Die eigDie = new Die();
       eigDie.setSides(8);
       int sameCount=0;
       System.out.println("\nRolling a pair of 8-sided dice 10 times:");
       for(int i=0;i<10;i++) {
           int e1=eigdie.roll();
           int e2=eigDie.roll();
           System.out.println(e1+"\t"+e2);
           if(e1==e2)
               sameCount++;
       }
       System.out.println("No of times both dies rolled same is "+sameCount);
       System.out.println("Enter 1 to continue");
       }while(keyIn.nextInt()==1);
}

}

Die:

import java.util.Random;

public class Die {
   private int sides;
   public void setSides(int i) {
       // TODO Auto-generated method stub
       this.sides=i;
   }
   public int roll() {
       Random ran = new Random();
       int x = ran.nextInt(this.sides)+1;
       return x;
   }

}

output:

Programmer: put your name here!!
Course: COSC 111, Winter '19
Lab: Exam 2, part 2
Due date: 3-20-19

Rolling a 6-sided die 20 times:

4   2   5   1  
4   1   3   1  
1   6   2   1  
1   6   4   2  
4   2   5   4  
Number of times six rolled is 2

Rolling a pair of 8-sided dice 10 times:
2   4
3   7
6   7
6   7
8   7
4   1
6   3
7   6
4   8
5   3
No of times both dies rolled same is 0
Enter 1 to continue
1
Rolling a 6-sided die 20 times:

4   2   6   2  
5   5   6   4  
2   2   2   4  
4   6   3   6  
3   3   3   5  
Number of times six rolled is 4

Rolling a pair of 8-sided dice 10 times:
6   2
2   1
8   5
7   8
3   5
2   3
7   6
5   3
4   5
6   6
No of times both dies rolled same is 1
Enter 1 to continue
0

screenshot of output:


Related Solutions

Suppose a red six-sided die, a blue six-sided die, and a yellow six-sided die are rolled....
Suppose a red six-sided die, a blue six-sided die, and a yellow six-sided die are rolled. Let - X1 be the random variable which is 1 if the numbers rolled on the blue die and the yellow die are the same and 0 otherwise; - X2 be the random variable which is 1 if the numbers rolled on the red die and the yellow die are the same and 0 otherwise; - X3 be the random variable which is 1...
Suppose you are rolling a fair four-sided die and a fair six-sided die and you are...
Suppose you are rolling a fair four-sided die and a fair six-sided die and you are counting the number of ones that come up. a) Distinguish between the outcomes and events. b) What is the probability that both die roll ones? c) What is the probability that exactly one die rolls a one? d) What is the probability that neither die rolls a one? e) What is the expected number of ones? f) If you did this 1000 times, approximately...
1. In 90 rolls of a six-sided die, the outcome of 1 appears 16 times. State...
1. In 90 rolls of a six-sided die, the outcome of 1 appears 16 times. State whether the difference between what occurred and what you would have expected by chance is statistically significant. Is the difference between what occurred and what is expected by chance statistically significant? No Yes 2. What is statistical inference? Why is it important? A.Statistical inference is the process of determining if the difference between what is observed and what is expected is too great to...
Problem 28. A fair six-sided die is rolled repeatedly and the rolls are recorded. When two...
Problem 28. A fair six-sided die is rolled repeatedly and the rolls are recorded. When two consecutive rolls are identical, the process is ended. Let S denote the sum of all the rolls made. Is S more likely to be even, odd or just as likely even as odd?
Consider the experiment of rolling a six-sided fair die. Let X denote the number of rolls...
Consider the experiment of rolling a six-sided fair die. Let X denote the number of rolls it takes to obtain the first 5, Y denote the number of rolls until the first 2, and Z denote the number of rolls until the first 4. Numerical answers are needed only for parts (a) and (b). Expressions are sufficient for parts (c), (d), and (e). a) E[X|Y = 1 or Z = 1] b) E[X|Y = 1 and Z = 2] c)...
A regular six-sided die and a regular eight-sided die are rolled to find the sum. Determine...
A regular six-sided die and a regular eight-sided die are rolled to find the sum. Determine the probability distribution for the sum of the two dice. Create a frequency histogram for the probability distribution and determine the expected sum of the two dice.
Suppose that you are offered the following "deal." You roll a six sided die. If you...
Suppose that you are offered the following "deal." You roll a six sided die. If you roll a 6, you win $15. If you roll a 3, 4 or 5, you win $1. Otherwise, you pay $4. a. Complete the PDF Table. List the X values, where X is the profit, from smallest to largest. Round to 4 decimal places where appropriate. Probability Distribution Table X P(X) b. Find the expected profit. $ ____ (Round to the nearest cent) c....
You roll a six- sided die. Find the probability of each of the following scenarios a....
You roll a six- sided die. Find the probability of each of the following scenarios a. Rolling a 6 or a number greater than 3 b. Rolling a number less than 5 or an even number c. Rolling a 2 or an odd number
You roll a fair six-sided die and don't look at it. What is the probability that...
You roll a fair six-sided die and don't look at it. What is the probability that it is a 5 given that your friend looks and tells you that it is greater than 2? Leave your answer as a fraction.
You are interested in the probability of the outcome when rolling a six-sided die. Answer the...
You are interested in the probability of the outcome when rolling a six-sided die. Answer the following questions using p to denote the probability of this outcome. (a) You suspect that for this die the outcome does not occur with the same probability as with a fair die. Formulate the null and alternative hypotheses based on which you may make a statistical inference regarding your suspicion. (b) You suspect that for this die the outcome occurs with greater probability than...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT