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

Thread: How to create a coin flip program

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to create a coin flip program

    ok well to start off this is my first time on this forum and hopefully im in the right section, im in a highschool computer programing class and would like to do something with my coin flip class over the winter break, i would like to create a program to click a button and it displayes an animation of a coin fliping and then landing on either heads or tails, this is my current code. (oh yeah using blueJ, i dont know if there is another java programing program just thought id mention that just incase.)

    public class Coin
    {
        // instance variables
        private double value;
     
        /**
         * Constructor for objects of class Coin
         */
        public Coin()
        {
            // initialise instance variables
            value = 0;
        }
     
        /**
         * flip will create a random number between 0 and 1 and store it in value
         *  
         */
        public void flip()
        {
           value = Math.random(); 
     
        }
     
        /** isHeads will return true if the value is less then 0.5
         * 
         *@return true if value < 0.5
         *              false otherwise
         */
        public boolean isHeads()
        {
            if (value < 0.5)
                return true;
            return false;
     
        }
     
            /** istails will return true if the value is greater then or equal to 0.5
         * 
         *@return true if value > 0.5
         *              false otherwise
         */
        public boolean isTails()
        {
            if (value >= 0.5)
                return true;
            return false;
     
        }
     
     
    }
    Last edited by helloworld922; December 20th, 2010 at 05:19 AM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: How to create a coin flip program

    The way I would recommend getting started with Java GUI programming is with Oracle's Java Swing tutorials (or a good book if you have access to one).

    I would recommend getting familiar with creating simple GUI interfaces (buttons, labels, custom painting, etc.) before attempting something like an animation.

    The animation part can be either difficult or easy, I would recommend starting out with a series of still coin shots and simply switching between the pictures. If you're feeling ambitious, you can try 3D animations via JOGL or LWJGL (jMonkeyEngine might also be a viable and easier alternative).

    I've never personally used BlueJ, I'm kind of an Eclipse fan myself Another good IDE is Netbeans. I believe all three are free (Eclipse and Netbeans are open source, not sure about BlueJ).

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    mrsaucy (December 20th, 2010)

Similar Threads

  1. Flipping a coin
    By jimboslice in forum Loops & Control Statements
    Replies: 2
    Last Post: October 18th, 2010, 11:13 AM
  2. Question about my coin toss program
    By CheekySpoon in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 9th, 2010, 04:14 AM
  3. Replies: 3
    Last Post: February 1st, 2010, 12:24 AM
  4. How to create exe file
    By sirimalla in forum Java Theory & Questions
    Replies: 6
    Last Post: November 1st, 2009, 04:07 AM
  5. how to create exe jar
    By ttsdinesh in forum Java Theory & Questions
    Replies: 1
    Last Post: September 27th, 2009, 08:21 AM