0
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,
            dollars,
            count,
            maxDollars,
            countAtMax;

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

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

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

                }
            }

           System.out.println
           ("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 ; 
    }
}
2
Contributors
1
Reply
14
Views
2 Months
Discussion Span
Last Post by rproffitt
0

You write you need help but only dump code and supply the class assignent text. I can't find what issue stopped you from completing the assignment. Remember that homework help follows certain rules since if we did the homework for you, you would not be learning and later will have deeper problems.

Read https://www.daniweb.com/programming/threads/435023/read-this-before-posting-a-question then add your problem and question.

Edited by rproffitt: Grammar

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.