Coin Progam Help

I need help writing a program that simulates the flipping of a coin 1000 times to see how often heads or tails come up. So far I have this:
import java.util.Random; //allows us to use random
     public class CoinClass
         //instance variables
           private int coin;
           private int heads=0;
           private int tails=1;
          //constructors
             public CoinClass()
          flip();
            // methods
          public int flip()
            face = (int)(Math.random()*2) + 1;
            public boolean heads()
             {      return(face==heads) 
           public boolean tails()
             {      return(face==tails) 
          public String toString()
           String faceName;
           if (face == heads)
         faceName = "Heads";
           else
         faceName = "Tails";
           return faceName;
     and
     public class CoinClassMain
          public static void main(String[] args)
         int numHeads=0;
         int numTails=0;
         int numFlips=0;
         int face;                              //keeps track of number of snake eyes
         CoinClassMain coin = new CoinClassMain();
              for(int i=0; i<=1000;i++)
                     coin.flip();
                       numFlips++;
     }But now I am at a lost as to what to do?
Any help would be appreciated!

Not quite sure I agree with prometheuzz about the counters, I think you've got them just right; but his constants for HEADS and TAILS are spot on. You can even make them public. Also, the "face" isn't really part of a coin, it's the result of a flip(), so you could simply have:public int flip() {
   return (int)(Math.random()*2) + 1;
}You also don't really need to do a flip() in your constructor; it's redundant.
Your main class is almost there. Try and think of it this way (a bit of pseudo-code here):
do 1000 times {
flip the coin
check the result
if it's heads {
do required stuff for a head
otherwise {
do required stuff for a tail
}

Similar Messages

  • HT5787 I updated my ipad but when I went into dragonvale it no longer recognized me and made me create a new account. As a result I can no longer access my park. I have tried to go into the Game Center to restore my park but i do not have any options.

    I updated my ipad but when I went into dragonvale it no longer recognized me and made me create a new account. As a result I can no longer access my park. I have tried to go into the Game Center to restore my park but i do not have any options to restore my old login/ account. Any tips?

    Buying a bag of coins might help...

  • TS1702 Help!! I downloaded some apps like games and when I want to buy coins to play and I try and put my pass word in it tells me this app belongs to another apple ID and I need to re buy the app but when I try it won't let me. What do I need to do???

    I downloaded some app from my iPod touch and the app downloaded no problem. But when I open the app to play a game and I have to buy something from the app like coins or up grade the app. And it won't let me it says app was open on a different apple I'd and that I needed to Purchase the app again and when I try and I find the same app the only thing it does is open it. I can't do anything. Then my iMessage I can't even hardly send messages because it always say failed Delivery when in fact I was able to send iMessage a couple of weeks ago to the same people that I can't now. And nothing has changed on there side. Please help me it's driving me crazy spending all that money on the iPod and I can't enjoy it 

    Please provide your operating system details along with the version of PS you are trying to download.
    If possible, paste a screenshot of the error that you get on Creative Cloud desktop app. FAQ: How do I capture and post a screen shot or video?
    ~ Arpit

  • My Creative Cloud subscription has expired, and I assigned the monthly payment, but I can not open any progam creative cloud, I need help how to solve this problem

    my Creative Cloud subscription has expired, and I assigned the monthly payment, but I can not open any progam creative cloud, I need help how to solve this problem

    Carlos-
    Start by signing out and back in to see if it will see the subscription: 
    How to sign in and sign out of creative cloud (activate/deactivate)
    If the apps are installed fine and close after launch see this link:
    CC applications close immediately after launch
    If the problem is something different, please let us know the error you see or what is happening on the screen so we can advise  you on a solution
    Pattie

  • TS3297 I want to buy the double coins from the game subway surfers! But they told me to contact the itunes support! I don't know why it's not working.. Please help! iPhone 4ss

    I want to buy the double coins from the game subway surfers! But they told me to contact the itunes support! I don't know why it's not working.. Please help! iPhone 4ss

    These are user-to-user forums, you are not talking to Apple here. You can contact iTunes support via this page and ask them why the message is appearing : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then probably Purchases, Billing & Redemption

  • When i try to buy 50k Coins in Jet Pack Joyride (3.99$) it says "Error al comprar" (Im from Costa Rica but my account is from USA) IDK what to do plz help me

    When i try to buy 50k Coins in Jet Pack Joyride (3.99$) it says "Error al comprar" (Im from Costa Rica but my account is from USA) IDK what to do plz help me.

    Hello Dovahkiin03,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at this article:
    iTunes Store: About In-App Purchases
    http://support.apple.com/kb/ht4009
    Best of luck,
    Mario

  • TS1424 My grandson was playing temple run and tried to down load coins. The IPAD frozen so he kept pushing the button and I now have a forty dollar bill for coins. Can I get some kind of help with this?

    My five year old grandson was laying Temple Run and tried to down load extra Coins.  The IPAD froze up so he kept hitting the button to get his coins. I ended up with a forty dollar bill for coins. Is there any way of geting this corrected? 

    In app purchases can be restricted in Settings/General/Restrictions.
    For all other things, try to contact iTunes support, maybe they can help.
    Apple - Support - Express Lane - Product Selection

  • HT4009 Also the free game draw something it made a double purchase of 1.99 when buying coins As I tether iPad 2 and iPhone 4s. The previous purchase on Cinemax was in the amount  Of 2.99 .... Something I tether. Thank you for your help in advance. Julie A

    Also the free game draw something it made a double purchase of 1.99 when buying coins
    As I tether iPad 2 and iPhone 4s. The previous purchase on Cinemax was in the amount
    Of 2.99 .... Something I tether. Thank you for your help in advance. Julie Ann Coulombe-
    Chew.

    Julie.....
    You are not talking to Apple here ... We are other iPad users like yourself and there is nothing that we can do for you. You will have to contact iTunes Support about any billing issues that you may have.
    http://www.apple.com/support/itunes/contact/

  • HT204088 Missing coins. Account charged!  Help please.

    I purchased coins within a game.  My account in the APP store was reduced by the purchase amount, but I didn't get the coins.
    Can someone please help me?

    Try contacting iTunes support and ask for help : http://www.apple.com/support/itunes/contact/ - click on Express Lane, then iTunes > iTunes Store

  • Hey I need a code for an Itunes 25$ gift card because when I scratched with a coin like it says it scratched the code right of and its unreadable. I need some help here.

    What I want is a code so I can buy my Lord of the Rings Extended Edition Videos because its upseting to see how easy it is to ruin these codes. The code was for 25$ for Itunes and now its ruined please help me its Christmas and I just got my Ipod Touch.

    iTunes Store: Invalid, inactive, or illegible codes
    http://support.apple.com/kb/TS1292

  • Toolbar "File Edit Vieuw History Bookmarks Tools Help" is suddenly 'gone". I have seen that via the Alt-coin this toolbar is shown again. But after closing FF en then again opening the toolbaar is again "gone". How to reach a permanent toolbar ?

    It seems to me that the problem is clearly written.

    This link should help - https://support.mozilla.com/nl/kb/Menubalk%20ontbreekt

  • Sys. Pref, Safari, Help, Utility Progams, Installers not working!

    Help! This is what's been going on for the past couple of days
    1) Safari opens to the home page, loads for a few secs and then gets stuck
    2) System Pref. window opens, but clicking on any icon doesn't do anything but give me a beach ball (can't change users to see if it's just my account)
    3) Help Viewer is just blank--more beach ball
    4) Disk Utility won't respond so I can check permissions
    5) Installer for 10.3.9 Upgrade doesn't work--more blank screens and beach balls
    6) Suitcase launches when the computer restarts. Sometimes it gets stuck and I force quit; sometimes it works fine
    6) Probably more stuff isn't reponding that I haven't even tried yet.
    Does any of this sound familiar?
    What does work: Explorer, AOL, Airport (but not the Airport Utility), most of my apps like IPhoto, System 9 programs, Font Book, QuickTime
    I recently installed the ITunes/Quick Time upgrade. Could that be it? I have trashed every Internet/Safari/HelpViewer/System preferences (p.list) and caches that I could find. Didn't help.
    OK, while I was typing this, I opened ITunes to see if it would work. It paused, didn't respond, then when I was about to Force Quit, it came on. Now all my issues seem resolved. Whew!
    What's that about? When you upgrade software, you should open it, so that preferences and stuff upgrade, too?
    I'm going to post this so that if anyone else encounters similar problems, they can try opening ITunes, if they just downloaded it.
    Boy, that saved me from reinstallation and Apple Care expense.
    Powerbook G4-15 inch   Mac OS X (10.3.9)  

    I can not imagine why you did not have the ..ical.plist, did the other files
    recreate themselfs look to see if they have, you did not empty the trash as i asked did you. If they have not, put them back.
    This is from Dr Smokes[ thank you] site- I hope it helps you & gwhite
    http://www.thexlab.com/faqs/resetlaunchservices.html#Anchor-Reset-11481
    Reset Launch Services under Panther
    1.) Quit all running applications.
    2.) Trash the com.apple.LaunchServices.6B.csstore file in the Macintosh HD
    Library > Caches folder. Type your Admin password if prompted to
    authenticate the deletion of this file. See Note [1].
    3.) Restart your Mac.
    4.) Log in to the affected account.
    5.) Empty the Trash.
    6.) Verify that the problem is solved. If not:
    a. Trash the com.apple.LaunchServices.plist file in the Home > Library > Preferences folder of the affected account. See Note [3].
    b. Repeat steps 1-5.
    do see the notes on his site.Make sure you understand the directions before you apply, as with all directions

  • After I purchased snoopy's street fairs' exclusive offer on 19th July12, I did not receive any  snoopy coins till now(Suppose to have 150 coins on the game). And APPLE charged me $1.00 on 19th, and charged $1.99 again on 21th July12, pls help

    Hi,
    After I purchased snoopy's street fairs' exclusive offer on 19th July12, I did not receive any snoopy coins till now(Suppose to have 150 coins on the game for $1.99). And APPLE charged me $1.00 on 19th, and charged $1.99 again on 21th July12, totally charged me $2.99, but still haven't recieved any snoopy coins in the game, it sounds unreasonable.
    thank you

    My daughter has had her Razr for about 9 months now.  About two weeks ago she picked up her phone in the morning on her way to school when she noticed two cracks, both starting at the camera lens. One goes completely to the bottom and the other goes sharply to the side. She has never dropped it and me and my husband went over it with a fine tooth comb. We looked under a magnifying glass and could no find any reason for the glass to crack. Not one ding, scratch or bang. Our daughter really takes good care of her stuff, but we still wanted to make sure before we sent it in for repairs. Well we did and we got a reply from Motorola with a picture of the cracks saying this was customer abuse and that it is not covered under warranty. Even though they did not find any physical damage to back it up. Well I e-mailed them back and told them I did a little research and found pages of people having the same problems. Well I did not hear from them until I received a notice from Fed Ex that they were sending the phone back. NOT FIXED!!! I went to look up why and guess what there is no case open any more for the phone. It has been wiped clean. I put in the RMA # it comes back not found, I put in the ID #, the SN# and all comes back not found. Yet a day earlier all the info was there. I know there is a lot more people like me and all of you, but they just don't want to be bothered so they pay to have it fix, just to have it do it again. Unless they have found the problem and only fixing it on a customer pay only set up. I am furious and will not be recommending this phone to anyone. And to think I was considering this phone for my next up grade! NOT!!!!

  • Synching iPod Touch with iTunes latest versions messes up e-mail progams on the Touch; help

    Twice now in the past week I have synched my 64GB latest model  iPod Touch with the latest version of iTunes and it has completely messed up my e-mail programs on the Touch; I cannot get or send e-mails.    I have to delete the e-mail accounts and then add them back in so that I can receive and send e-mails.  What has caused this and how can I eliminate this from happening in the future when I sync?  Thank you for your help.
    carol

    Yes, I find it strange, too but it has happened both times I have synched the Touch in the past week.  iTunes was updated right before the first time this happened.     I have Verizon for my e-mail and it would not work on the Touch  but I was able to send and receive emails on my desk top.   It is frustrating to say the least to spend time deleting and then adding the e-mail accounts to the Touch.

  • HT1491 How do I block my kids from purchasing in app content on my ipod?  I don't want them buying 100 coins for $2.49, etc.  Please help!

    Hello!  How do I block my kids from purchasing in app content from games when they are playing on our ipod?  I just got it last week and haven't figured that out.  Can I get charged from them clicking "buy"  without my signing in?  HELP!   Thanks.

    Set a Restriction for purchases, including in-app purchases. See:
    iOS: Understanding Restrictions

Maybe you are looking for

  • ITunes 6.4 will not install?  Help!

    Good evening everyone, Every time iTunes opens it asks me to install iTunes 6.4 (I believe) or the newest version.  It begins to install and gets maybe about 75% done before an error pops up saying that the network I am on does not contain the resour

  • Error invoking bpel partner link from bpel process

    hello, i try to invoke a bpel web service (deployed correctly) from another bpel process. I've this error: Cannot find resource. Context: http://orcldemo.localdomain:9700/orabpel/xmllib/ws-addressing.xsd I've tried to add my wsdl to: \\orcldemo\orabp

  • Illustrator CC Crashes on Launch, OSX 10.9

    Dear community, I just purchased Adobe CC on my new MacBook Pro retina 15 inch. I am running Mac OSX 10.9. Photoshop and LightRoom were fine. I was never able to launch illustrator. I did have Creative Suit CS4 installed prior. The suit was uninstall

  • Keynote to iWeb problem

    Hi, Just purchased iWork 08 and trying to send my Keynote presentation to iWeb but the function is greyed out - it is not allowing me to do this. Any idea why?

  • I can't install Adobe Flash Player 11.8.800.174

    I get 50% through and get a message to close Internet Explorer and continue. I do so, but the same message appears.