Lab #6 will require you to write a trivial class representing a dice. Your TA wi
ID: 3654889 • Letter: L
Question
Lab #6 will require you to write a trivial class representing a dice. Your TA will assist you with each step of development. You will be give a starter file that is mostly written. You will just add a couple lines of code to complete the Die class. The main program tester file. Use as is. Do not modify /* DieTester.java Creates and exercises the methods in the Die class You must have a compiling Die.java file in your directory DO NOT MODIFY THIS TESTER PROGRAM */ import java.util.*; import java.io.*; public class DieTester { public static void main( String args[] ) { int seed1 = Integer.parseInt( args[0] ); int seed2 = Integer.parseInt( args[1] ); Die d1 = new Die( seed1 ); // cmd line should pass in diff vals so the dice do not produce identical pairs Die d2 = new Die( seed2 ); for (int i=0; i<10 ; ++i ) { System.out.print("d1: " + d1.roll() + " d2: " + d2.roll() ); System.out.println(); } System.out.println("Roll history for d1: " + d1.history() ); System.out.println("Roll history for d2: " + d2.history() ); } // END MAIN } // END DIETESTER The Die.java class definition file. You must fill in the missing pieces /* STARTER FILE FOR r Die.java class definition file */ import java.util.*; import java.io.*; public class Die { Random r; // rollHistogram: // [0] is never used, // [1] accumulates number of rolls resulting in a 1 // [2] accumulates number of rolls resulting in a 2 // ... // [6] accumulates number of rolls resulting in a 6 int[] rollHistogram = new int[7]; // [0] never used public Die( int seed ) // seed should be a positive int { r= new Random( seed ); } public int roll() { int face=0; // MUST BE OVER WRITTEN with int between 1..6 inclusive // you add the line of code to produce a random number between // 1..6 inclusive with equal probablity of any of the 6 numbers // store that number into the face variable // YOUR LINE OF CODE HERE // you add the line of code to increment the proper rollHistogram counter for this result // YOUR LINE OF CODE HERE return face; } // prints the histogram of frequencies for each die face public String history() { String histoStr = ""; for ( int i=1 ; i<7 ; ++i) histoStr += i + "'s rolled: " + rollHistogram[i] + " "; return histoStr; } } // END DIE CLASSExplanation / Answer
import java.util.Random; public class DiceRolling { public static void main( String[] args) { Random randomNumbers = new Random(); // Generates random numbers int[] array = new int[ 7 ]; // Declares the array //Roll the die 36,000 times for ( int roll = 1; rollRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.