In: Computer Science
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
}
}
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: