Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Roll the Dice_ Console

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Roll the Dice_ Console

    Console
    Welcome to the Paradise Roller application

    Roll the dice? (y/n): y

    Roll 1:
    2
    5
    Craps!

    Roll again? (y/n): y

    Roll 2:
    2
    1

    Roll again? (y/n): y

    Roll 3:
    4
    6

    Roll again? (y/n): y

    Roll 4:
    6
    6
    Box cars!

    Roll again? (y/n): y

    Roll 5:
    1
    1
    Snake eyes!

    Roll again? (y/n): n
    Operation
    • If the user chooses to roll the dice, the application rolls two six-sided dice, displays the results of each, and asks if the user wants to roll again.
    Specifications
    • Create a class named Die to store the data about each die. This class should contain these constructors and methods:
    public Die() // default to a six-sided die
    public Die(int sides) // allow a variable number of sides
    public void roll()
    public int getValue()

    • Create a class named PairOfDice to store two dice. This class should contain two instance variables of the Die type, an instance variable that holds the sum of the two dice, and these constructors and methods:
    public PairOfDice() // default to six-sided dice
    public PairOfDice(int sides) // allow a variable number of sides
    public void roll()
    public int getValue1() // get value of die1
    public int getValue2() // get value of die2
    public int getSum() // get the sum of both dice
    • You can use the random method of the Math class to generate a random number from 1 to the number of sides on a die like this:
    int value = (int) (Math.random() * sides);
    • Create a class named DiceRollerApp that uses the PairOfDice class to roll the dice. This class should display special messages for craps (sum of both dice is 7), snake eyes (double 1’s), and box cars (double 6’s). For this application, assume that two six-sided dice are used.
    • Create a class named Validator that contains static methods that can be used to validate the data in this application.
    /
    /
    /
    /
    //Am suppose to use netbean to create the above codes but am lost as to how i go about it


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Roll the Dice_ Console

    Moved from Introduction section.

    Start by creating the classes listed in the assignment with the methods that each is supposed to have. Leave the insides of the methods empty for now except for those that return a value just return a constant value to make the compiler happy. For example:
    public int getValue1() {  // get value of die1
      return 1;  // hardcoded number for now
    }
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Roll the Dice_ Console

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers.

Similar Threads

  1. Please Help: Random Dice Roll:
    By dbs360 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 16th, 2013, 02:32 PM
  2. Roll Dice Program Button
    By shen_punkz21 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 28th, 2013, 03:51 PM
  3. Can't figure out how to roll individual dice.
    By mortiz492 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 19th, 2012, 02:07 PM
  4. HELP random generator with roll() and print() method
    By disc_dido in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 18th, 2011, 01:50 PM