import java.util.Scanner;

public class LuckySevens {
    private int diceLength;
    private int rolls;
    private int sides;
    private int numRolls = 0;

    public static void main (String [] args) {

        Scanner reader = new Scanner(System.in);

        int diel, die2,

            System.out.print("How many dollars do you have? ");
            dollars = reader.nextInt();

            maxDollars = dollars;
            countAtMax = 0;
            count = 0 ;

            while (dollars > 0) {
                diel = (int)(Math.random() * 40 )+ 1 ; 
                die2 = (int)(Math.random() * 40 )+ 1 ; 
                if (diel + die2 == 7)
                dollars +=4;
                dollars -=1;
                if (dollars > maxDollars) {
                    maxDollars = dollars; 
                    countAtMax = count; 


           ("You are broke after " + count + " rolls.\n" + 
           "You should have quit after " 
           + countAtMax +
           " rolls when you had $" + maxDollars + ".");


I need help with my dice class and putting objects to modify the LuckySevens class:

Project Description: Redo the Lucky Sevens dice-playing program from the last unit so that it uses two dice objects. That is, design and implement a Dice class.

Each instance of this class should contain the die's current side. There should be an accessor method for the die's current value. The method roll is the only mutator method.

Then within your LuckySevens class, instantiate two Dice objects, and just roll them whenever you need a new value for each turn. Don't create two new Dice objects every time you need to roll the dice (would you go to the store every time to get a brand new pair of dice whenever you needed to roll them?). Just roll the ones you already have.

Note that much of the code that you need is already in the original LuckySevens class. You are just breaking out the dice rolling function into its own standalone class, which could be used by other objects if needed.

When you are finished with this project, show me your new LuckySevens class that uses a separate Dice object.

public class Dice
    private int dice ;

    private int  side;
    private int numRolls = 0;
    public int Roll()
        return (int)(Math.random() * 6 )+ 1 ; 


    public int getside()

        return side ; 
3 Weeks
Discussion Span
Last Post by rproffitt
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.