Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am supposed to write a trivial class representing a dice.so i have all my code

ID: 3654916 • Letter: I

Question

I am supposed to write a trivial class representing a dice.so i have all my code ready but it's not compiling. It says non static method nextInt(Int) cannot be referenced from a static context on the line where i had int rollHistogram= 1 + Random.nextInt(6)..what am i doing wrong? Please help.. 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 { Random 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 int rollHistogram = 1 + Random.nextInt(6); // YOUR LINE OF CODE HERE rollHistogram++; // 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 CLASS

Explanation / Answer

It should be int rollHistogram = 1 + r.nextInt(6); not Random.nextInt();

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote