I am supposed to fill in the lines of the missing code, it\'s basically writing
ID: 3655128 • Letter: I
Question
I am supposed to fill in the lines of the missing code, it's basically writing a trivial class representing a dice, the starter file is below. Can anyone help me with the missing codes please. /* 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
package com.cramster.nov5; 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 face = r.nextInt(6) + 1; // you add the line of code to increment the proper rollHistogram counter for this result // YOUR LINE OF CODE HERE rollHistogram[face]++; return face; } // prints the histogram of frequencies for each die face public String history() { String histoStr = ""; for ( int i=1 ; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.