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 5 of 5

Thread: Help with creating a dice rolling program in Java

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with creating a dice rolling program in Java

    I need to Write a program that creates a Dice object.
    Your program will involve two separate classes in different files:
    One class for the main method
    Another class describing the Dice object
    The Dice class should have fived methods (and a single class variable for storing the number on the dice):
     A constructor method with the same name as the class
     A roll( ) method for rolling the dice
     A getValue( ) method for returning the value showing on the dice
     An isEven( ) method which checks if the value is even or odd
     An isHigh( ) method which checks if the value is high or low
    The main application should do the following:
    1. Create a Dice object
    2. Roll the dice every time the user hits enter
    3. Print out the new value showing on the dice
    4. Print out whether the value is even or odd, high or low

    So far I have this. Just wondering if someone could help me with the remaining methods

    import java.util.Scanner*;

    public class Dice {

    public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    Dice dice1 = new Dice();

    System.out.println("dice1 is " + dice1.roll());
    }
    }
    public class Dice{

    int roll(){

    return 1 + (int)(Math.random()* 6)+1;
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Help with creating a dice rolling program in Java

    Ask a specific question, get a specific answer. You posted an assignment and some code, but what are you having trouble with?

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with creating a dice rolling program in Java

    Hello - I was interested in this problem and am new to objects so I looked up an article (in comments) then adapted your code somewhat. Did your code actually roll and produce output or was it "stuck"? Anyway, this will do some of what the specs wanted but not all as I wanted to try some other stuff. That article is good. Post what you came up with as I am interested.

    --
    ...edited by moderator
    Last edited by copeg; October 25th, 2011 at 11:56 PM.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Help with creating a dice rolling program in Java

    darter, please read the forum rules and the following article: http://www.javaprogrammingforums.com...n-feeding.html

  5. #5
    Junior Member
    Join Date
    Sep 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with creating a dice rolling program in Java

    Well done. The working code, outside sources and explanatory comments are definitely gone. Although I don't think the OP would ever had seen it (he seemed to have left a week ago) there would have remained the possibility that other people interested in the problem might have. Your swift action prevents this later possibility from ever occurring.

Similar Threads

  1. Java Dice Program
    By ebone in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 22nd, 2011, 11:07 PM
  2. [SOLVED] Dice Rolling Simulation
    By SnarkKnuckle in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 12th, 2011, 06:51 PM
  3. Creating a java program to "Beat" Snake web app?
    By AkOndray in forum AWT / Java Swing
    Replies: 2
    Last Post: December 5th, 2010, 12:36 AM
  4. Dice Program Help
    By Bradshjo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 2nd, 2010, 07:50 AM
  5. Creating program Blackjack - Dr.Java
    By TheUntameable in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 20th, 2010, 12:54 PM