Hello all. I've been staring at this program I need to do for the better part of two days now. I'm relatively new to coding, but have had almost no trouble at all until this. After reading up as much as I could on classes and objects, I still can't figure out exactly what the syntax is that I need to use.
Basically I need a die object called into a diepair class and then that called into a simulation class. It needs to tally up the totals for each die roll. I've been given the starting code and have even put in the directions I was given: I'm sure this is relatively simple and yet still can't seem to figure it out.
import java.util.*; public class Die { private Random rgen; private int face; public Die(Random gen) { //needs to have a stored reference to the random # generator and a face value between 1 and 6 } public void roll() { face = rgen.nextInt(1-6); //needs the random integer generated and stored in the face field } public int getFace() { return face; //face needs to be returned } } import java.util.*; public class DicePair { public Die die1, die2; int doubles=0, sum; Random rgen; public DicePair (Random gen) { Die die1 = new Die(rgen); Die die2 = new Die(rgen); //construct two die objects and pass the specified random number generator to them } public void roll() { //roll them } public int getSum() { sum = die1(getFace) + die2(getFace); //return the sum of the face values } public boolean isDoubles() { if(die1(getFace) == die2(getFace)) doubles = doubles + 1; //return true if double } } import java.util.*; public class Simulation { private Random gen; private DicePair pair; private int[] tally; private int doubles; public Simulation() { DicePair pair = new DicePair(); tally = new int[2-12]; //create the random number generator, dicepair object, and array to tally the sums } public void simulate(int times) { doubles = 0; for (count = 0; sim <= 200; ++ count) { } //initialize tallies and doubles to zeros, simulate rolls, and tally the number of rolls and count doubles } public void report() { System.out.printf("%nSum Tally%n"); for (count = 2; count < 13; ++count) { System.outprintf ("%3d %8d ", count, tally[count]); for (star = 0; star < tally[count]; ++star) { System.out.printf("*"); } System.out.printf("%n"); } //print a report of the simulation } public static void main(String[] args) { Simulation sim = new Simulation(); sim.simulate(200); sim.report(); } }
If someone could help me out here, I don't know if it's the syntax that's confusing me or what, but it's been driving me crazy.