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: Please help me with the Coin flip rogram.

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

    Post Please help me with the Coin flip rogram.

    Part 1: Coin Toss Game
    In this you will create a program that models coin objects. The coins
    will be used in a coin toss game to win a sum of money equal to double the
    amount the user bets before tossing the coin. The user will also enter their guess
    as either 0 for heads or 1 for tails (both as integers).
    Your solution should consist of two classes:
    1. The Coin class. Each coin will be initialized with a bet value and will contain
    two methods (plus a constructor):
     flip() : tosses the coin and returns either a 0 for heads or a 1 for tails. You can
    use the Math class from the java.util package to generate random numbers
    and simulate a coin toss. The Math.random() method returns a random
    floating point number between 0.0 and 1.0. You could call it "heads" if the
    number is greater than 0.5, and tails otherwise.
     getPrizeValue(): returns two times the initial bet value for this particular coin.
    2. The GamePlayer class that prompts the user (via a main method) to enter
    their bet amount in dollars and then choose either heads or tails. The
    GamePlayer should then create a new Coin with the userís bet amount, flip
    the coin and return a statement either saying that the user lost or that the
    user won, and the amount of the prize . Prizes should be formatted as
    dollar values to two decimal places.

    Sample Output (win):
    Enter your initial bet value for the coin toss to the nearest dollar
    20
    Now enter your guess, enter 0 for heads or 1 for tails
    1
    You won! Your prize amount is:
    $40.00
    Sample Output (loss):
    Enter your initial bet value for the coin toss to the nearest dollar
    30
    Now enter your guess, enter 0 for heads or 1 for tails
    1
    You lost...please play again


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Please help me with the Coin flip rogram.

    What will be your first step in solving the problem?

Similar Threads

  1. [SOLVED] Java Noob: Coin Toss Simulator (no GUI)
    By bgroenks96 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 4th, 2011, 10:28 PM
  2. Project Coin and java 7
    By Kerr in forum The Cafe
    Replies: 4
    Last Post: March 27th, 2011, 10:53 AM
  3. How to create a coin flip program
    By mrsaucy in forum Java Theory & Questions
    Replies: 1
    Last Post: December 20th, 2010, 04:31 AM
  4. Flipping a coin
    By jimboslice in forum Loops & Control Statements
    Replies: 2
    Last Post: October 18th, 2010, 11:13 AM
  5. Question about my coin toss program
    By CheekySpoon in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 9th, 2010, 03:14 AM

Tags for this Thread