Program doesn't recognise keyboard input. PLease help.

Hi guys,
I managed with help from some of you to build my Dice Game.
It works the way it should be however I still have a small issue.
It should be working in a way that when user in the beginning puts 'r' the dice roll is performed. At the moment no matter what I put and the press Enter the dice roll is performed.
The same is for Roll and Hold. After each dice throw a human can either roll (press 'r') or hold (press 'h').
If I press 'h' then it works fine- computer turn begins, but when I just press enter it rolls again.
why is that?
Below is the code, thanks in advance for any help!
import java.util.Scanner; 
public class Assignment 
     Boolean humanTurn = true; 
     Boolean computerTurn = true; 
     int dice; 
     int humanTurnPoints, computerTurnPoints; 
     int humanTotalPoints = 0;
     int computerTotalPoints = 0;     
     public void roll() 
         dice = (int)(Math.random()*6) + 1;                  
     public int humanTurnScore() 
                 humanTurnPoints = dice + humanTurnPoints; 
                 System.out.println("You threw: " + dice);
                 System.out.println("You have scored: " + humanTurnPoints + " in your turn."); 
             } return humanTurnPoints; 
     public void humanTurnZero()
          humanTurnPoints = 0;
     public int computerTurnScore() 
                 computerTurnPoints = dice + computerTurnPoints; 
                 System.out.println("Computer has scored: " + computerTurnPoints + " in its turn."); 
             } return computerTurnPoints; 
      public void computerTurnZero()
               computerTurnPoints = 0;
     public Assignment() 
         humanGame(); 
         if(!humanTurn) 
             computerTurn(); 
     public int humanGame()
         System.out.println("To start the game please press 'r'."); 
         Scanner key = new Scanner(System.in); 
         String start = key.nextLine(); 
         if(!start.equalsIgnoreCase("R"))
                   System.out.println("To begin please press 'r'.");
         if(start.equalsIgnoreCase("R"))
                         System.out.println("You pressed 'r'."); 
                         System.out.println("Lets start.");          
         do{ 
                 roll();     
                 if(dice == 1) 
                     System.out.println("You got 1 and you lost your turn.");
                     System.out.println("Computer's GRAND TOTAL score is: " + computerTotalPoints);
                     humanTurnZero();           
                     computerTurn(); 
                 else if(dice != 1)
                     humanTotalPoints += dice;      
                          if(humanTotalPoints >= 100)   
                                 System.out.println("You threw: " + dice);
                                 System.out.println("Your GRAND TOTAL score is: " + humanTotalPoints);
                                   System.out.println("Congratulations, you win!"); 
                                   System.exit(0); 
                     humanTurnScore();     
                     System.out.println("Your GRAND TOTAL score is: " + humanTotalPoints); 
                     System.out.println("Computer's GRAND TOTAL score is: " + computerTotalPoints);
                     System.out.println("You can hold or roll again."); 
                     System.out.println("To roll again press 'r' or 'h' to hold."); 
                     Scanner keyboard = new Scanner(System.in); 
                     String choice = keyboard.nextLine(); 
                     if(choice.equalsIgnoreCase("r")) 
                         System.out.println("You pressed 'r'."); 
                         System.out.println("Lets roll again.");  
                         roll();          
                     if(choice.equalsIgnoreCase("h")) 
                         System.out.println("You pressed 'h' and loose your turn.");
                         System.out.println("Your Grand total is: " + humanTotalPoints);
                         humanTurnZero(); 
                         computerTurn(); 
            }while(humanTurn);    
         return dice; 
public int computerTurn() 
     System.out.println("Now it's computer turn."); 
     do { 
         roll(); 
         if(dice != 1) 
               computerTotalPoints += dice;
                    if(computerTotalPoints >=100) 
                           System.out.println("Computer threw: " + dice);
                           System.out.println("Computer's GRAND TOTAL score is: " + computerTotalPoints);
                             System.out.println("Game Over! the computer wins"); 
                             System.exit(0); 
             System.out.println("Computer threw: " + dice);
             System.out.println("Computer's GRAND TOTAL score is: " + computerTotalPoints);
             System.out.println("Your Grand total is: " + humanTotalPoints);
             computerTurnScore(); 
             roll(); 
         if(dice == 1)  
             System.out.println("Computer thrown 1 therefore it's your turn now."); 
             computerTurnZero(); 
             humanGame(); 
         if(computerTurnPoints >= 20) 
             System.out.println("Computer scored already " + computerTurnPoints + " you'd better start to focus."); 
             System.out.println("Please play again"); 
             humanGame(); 
     }while (computerTurn); 
     return dice; 
public static void main(String[] args) 
     new Assignment(); 

Hi,
Thanks for that but I don't really understand that concept roll().
I did what you were saying, but now when the program just started and i press something else instead of 'r' the program terminates.
When I press correctly 'r' in the beginning and after that is human turn i pressanything else except 'r' or 'h' program continues to behave like I pressed 'r'.
public int humanGame()
         System.out.println("To start the game please press 'r'."); 
         Scanner key = new Scanner(System.in); 
         String start = key.nextLine(); 
         if(!start.equalsIgnoreCase("R"))
                   System.out.println("To begin please press 'r'.");
         if(start.equalsIgnoreCase("R"))
                         System.out.println("You pressed 'r'."); 
                         System.out.println("Lets start.");          
         do{ 
                 roll();     
                 if(dice == 1) 
                     System.out.println("You got 1 and you lost your turn.");
                     System.out.println("Computer's GRAND TOTAL score is: " + computerTotalPoints);
                     humanTurnZero();           
                     computerTurn(); 
                 else if(dice != 1)
                     humanTotalPoints += dice;      
                          if(humanTotalPoints >= 100)   
                                 System.out.println("You threw: " + dice);
                                 System.out.println("Your GRAND TOTAL score is: " + humanTotalPoints);
                                   System.out.println("Congratulations, you win!"); 
                                   System.exit(0); 
                     humanTurnScore();     
                     System.out.println("Your GRAND TOTAL score is: " + humanTotalPoints); 
                     System.out.println("Computer's GRAND TOTAL score is: " + computerTotalPoints);
                     System.out.println("You can hold or roll again."); 
                     System.out.println("To roll again press 'r' or 'h' to hold."); 
                     Scanner keyboard = new Scanner(System.in); 
                     String choice = keyboard.nextLine(); 
                     if(choice.equalsIgnoreCase("r")) 
                         System.out.println("You pressed 'r'."); 
                         System.out.println("Lets roll again.");  
                         roll();          
                     if(choice.equalsIgnoreCase("h")) 
                         System.out.println("You pressed 'h' and loose your turn.");
                         System.out.println("Your Grand total is: " + humanTotalPoints);
                         humanTurnZero(); 
                         computerTurn(); 
            }while(humanTurn);    
         return dice; 
              }return dice;
     }

Similar Messages

  • I have a family video DVD that was originally on tape, but is now on disc. I want to import it onto my MacBook to edit and store. However the files are IFO, BUP and VOB and the Mac is saying 'unable to import' as it doesn't recognise the file. Help !!

    I have a family video DVD that was originally on tape, but is now on disc. I want to import it onto my MacBook to edit and store. However the files are IFO, BUP and VOB and the Mac is saying 'unable to import' as it doesn't recognise the file. Help please !!!!!

    Those are the constituent parts of a standard mpeg2 DVD. Storing them is easy: just copy the folder to your hard drive and they will play in DVD player or VLC.
    But that format is not intended for editing. To do so:
    You need to convert the VOB files in the TS-Folder of the DVD back to DV which iMovie is designed to handle. For that you need mpegStreamclip:
    http://www.squared5.com/svideo/mpeg-streamclip-mac.html
    which is free, but you must also have the  Apple mpeg2 plugin :
    http://store.apple.com/us/product/D2187Z/A/quicktime-mpeg-2-playback-component-f or-mac-os-x
    (unless you are running Lion in which case see below))
    which is a mere $20.
    Another possibility is to use DVDxDV:
    http://www.dvdxdv.com/NewFolderLookSite/Products/DVDxDV.overview.htm
    which costs $25.
    For the benefit of others who may read this thread:
    Obviously the foregoing only applies to DVDs you have made yourself, or other home-made DVDs that have been given to you. It will NOT work on copy-protected commercial DVDs, which in any case would be illegal.
    And from the TOU of these forums:
    Keep within the Law
    No material may be submitted that is intended to promote or commit an illegal act.
    Do not submit software or descriptions of processes that break or otherwise ‘work around’ digital rights management software or hardware. This includes conversations about ‘ripping’ DVDs or working around FairPlay software used on the iTunes Store.
    If you are running Lion:
    From the MPEG Streamclip homepage
    The installer of the MPEG-2 Playback Component may refuse to install the component in Lion. Apple states the component is unnecessary in Lion onwards, however MPEG Streamclip still needs it. See this:
    http://support.apple.com/kb/HT3381
    To install the component in Lion, please download MPEG Streamclip 1.9.3b7 beta above; inside the disk image you will find the Utility MPEG2 Component Lion: use it to install the MPEG-2 Playback Component in Lion. The original installer's disk image (QuickTimeMPEG2.dmg) is required.
    The current versions of MPEG Streamclip cannot take advantage of the built-in MPEG-2 functionality of Lion. For MPEG-2 files you still need to install the QuickTime MPEG-2 Playback Component, which is not preinstalled in Lion. You don't have to install QuickTime 7.

  • Hi, I am wondering why my iphone won't send pictures through messages, I have MMS on and I have tried sending it with 3G on aswell and still doesn't work. Someone please help me :)

    Hi, I am wondering why my iphone won't send pictures through messages, I have MMS on and I have tried sending it with 3G on aswell and still doesn't work. Someone please help me :)

    Hey lozza567,
    Thanks for the question. I understand that you are experiencing issues sending MMS messages. The following resource may provide a solution:
    iOS: Troubleshooting Messages
    http://support.apple.com/kb/ts2755
    Issues with sending and receiving MMS
    You will need these to send and receive MMS:
    - An iPhone 3G or later.
    - iOS 3.1 or later.
    - A cellular data connection. MMS isn't available if you are using only Wi-Fi.
    - A domestic MMS plan from your cellular provider. You may need an international messaging plan to send MMS to an international contact. Contact your carrier for more information.
    - A roaming MMS when using a cellular provider's network different from your billing cellular provider's network. Learn more about roaming and contact your carrier for more information.
    To resolve issues with sending and receiving MMS, follow these steps first
    1. Go to Settings and turn airplane mode off.
    2. Go to Settings > Messages and turn MMS Messaging on.
    3. Go to Settings > Cellular and turn Cellular Data on.
    4. Go to Settings > Cellular and turn Data Roaming on if you are roaming on a cellular provider network different from your billing provider's network.
    5. Verify that you have a cellular data connection in the status bar at the top left of your iPhone.
    6. Go to Settings and turn Wi-Fi off. Open Safari and navigate to www.apple.com to verify that you have a data connection. Turn Wi-Fi back on to continue using Wi-Fi for other features. If your cellular data connection isn't available, follow these steps.
    7. Verify that you can send and receive SMS. If you are unable to send and receive SMS, see the "Issues with sending and receiving SMS" section, above.
    8. MMS may not be available while on a call. Only 3G and faster GSM networks support simultaneous data and voice calls. Learn more about which network your phone supports.
    9. Restart your iPhone.
    10. Tap Settings > General > Reset > Reset Network Settings on your iPhone.
    11. Reseat your SIM card.
    If you are still unable to send or receive MMS, follow these steps
    1. Make sure that the contact trying to message you isn't blocked in Settings > Messages > Blocked.
    2. Go to Settings > Messages and turn on group messaging if you are sending a group message.
    3. Make sure that you are using the area code with the contact's phone number. When sending messages internationally, you also need the contact's international code.
    4. Verify a "Pay as you go" MMS plan has enough available balance. Contact your carrier if unsure of your MMS plan or available balance.
    5. If the issue occurs with a specific contact or contacts, back up or forward important messages and delete your current messaging threads with the contact. Create a new message to the contact and try again.
    6. If the issue occurs with a specific contact or contacts, delete and re-create the contact from the Contacts application. Create a new message to the newly created contact and try again.
    7. Back up and restore your iPhone as new.
    8. If your carrier has recently ported your phone number, the porting process may not be complete. Contact your carrier to confirm that the porting process is complete.
    9. Contact your carrier to verify that you are provisioned to send SMS and are in an area with cellular coverage.
    10. Contact your carrier to verify that there are no blocks or filters placed on your wireless account preventing you from sending SMS.
    11. Your carrier may require APN settings to be modified to use MMS. Learn more about when you should adjust APN settings.
    Thanks,
    Matt M.

  • HT5312 The option to reset security information tab isn't showing up for me, is there I way that I can make it show up. I have a rescue email address and it still doesn't show up. Please help!

    The option to reset my security information tab is not available for me, I have a rescue email address in place and it still doesn't show up. Please help!

    You need to ask Apple to reset your security questions; ways of doing so include clicking here and picking a method for your country, and filling out and submitting this form.
    (96335)

  • Hello, I have an iPad Mini WiFi Cellular white 16Gb and I puted my sim inside it but, I cant read the text message that I recieve in the Sim. What can i do? And I can't put the sim in a cellphone coz it doesn't recognize it. Please help me! Thank you.

    Hello, I have an iPad Mini WiFi Cellular white 16Gb and I puted my sim inside it but, I cant read the text message that I recieve in the Sim. What can i do? And I can't put the sim in a cellphone coz it doesn't recognize it. Please help me! Thank you.

    iPads do not do SMS.

  • I just got a new ipad mini and I can't find the parenthesis button on the keyboard.  Please help!

    I just got a new ipad mini and I can't find he parenthesis button the keyboard. Please help!

    Press the .?123 button at the bottom left, then you'll see them in the middle of the second row.

  • After i update the 10.10.2 OS X Yosemite my iPhoto stops working. In the warning that appears when I try to open the app says that happened a mistake because of this update. I reinstalled the app but doesn't work anyway. Please, HELP!

    after i update the 10.10.2 OS X Yosemite my iPhoto stops working. In the warning that appears when I try to open the app says that happened a mistake because of this update. I reinstalled the app but doesn't work anyway. Please, HELP!

    I already tried that but it doesn't work. Appears a warning saying: "See the developer to make sure that iPhoto works with this version of OS X. You may need to reinstall the application. Be sure to install all available updates in the application and OS X."

  • HT1338 i qualified for free mac os upgradation program but i lost the password. please help me out...

    i qualified for free mac os upgradation program but i lost the password. please help me out...
    my apple id is: [email protected]

    What password, you don't need a password... Just go here...
    https://uptodate.apple.com/UtdPrepareAction?program=Mountain%20Lion&locale=en_us

  • I qualified for free mac os upgradation program but i lost the password. please help me out...

    i qualified for free mac os upgradation program but i lost the password. please help me out...

    http://support.apple.com/kb/HE57

  • My CS6 photoshop started showing cannot perform function programming error then it started freezing please help?

    My CS6 photoshop started showing {cannot perform function programming error}
    then it started freezing please help?

    Supply pertinent information for quicker answers
    The more information you supply about your situation, the better equipped other community members will be to answer. Consider including the following in your question:
    Adobe product and version number
    Operating system and version number
    The full text of any error message(s)
    What you were doing when the problem occurred
    Screenshots of the problem
    Computer hardware, such as CPU; GPU; amount of RAM; etc.

  • IMac doesn't recognise keyboard (wireless and usb)

    Hi!
    I've seen similar posts, but non had advice that helped. I'm having this problem for a weeks, before the problem everything worked perfectly. My Apple wireless keyboard start to act strange. I couldn't type some letters, so i put new batteries and still the same problem. When I type for example letter S it appears on screen as DS, the light on the shift key doesn't turn off when pressed. I have also tried to unpair it but now i can't even pair it with the computer any more.
    I have bought A4tech KD-126 keyboard which was recognisable by the computer till first time i unplug it. After i tried to plug it in all usb ports, led lights on the keyboard are working but computer doesn't recognise it as a keyboard.
    So I have tested other keyboard which my husband is using (A4tech KB-28G) and this only keyboard that works for now.
    I want to make A4tech KD-126 keyboard working at least.
    Please Help!!   

    Reset the NVRAM/PRAM and Reset the SMC, then try the wired keyboard again.

  • Adobe Reader 10.1.2 not recognising keyboard input

    Hi,
    I'm having a problem with Adobe Reader X on Windows 7 Ultimate. Adobe Reader is not recognising any keyboard input, so I'm unable to type in a page number to jump to that page, the alt key doesn't bring up the menu, even Alt+F4 doesn't close the application etc. Has anybody experienced this problem, and if so, is there a solution out there?
    I've tried both repairing the installation, and doing a new install, both of which have failed to rectify the problem.
    Thanks.

    Sorry for the confusion. Please try the following steps:
    1. Launch Notepad and type in following:
    Windows Registry Editor Version 5.00
    [-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.exe]
    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.exe]
    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.exe\OpenWithList]
    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.exe\OpenWithProgids]
    "exefile"=hex(0):
    2. Click on File > Save As
    3. In the new dialog that appears:
    Select All Files in the Save as type list, and then type C:\Exe.reg in the File name box.
    Select Unicode in the Encoding list. Save it and remember the file location.
    4. Open My Computer and double click on the C: icon
    5. You will see a file by the name of "Exe.reg". Double click on the same and click Yes on any dialog that appears.
    6. Once completed, restart the computer and your problem should be resolved.
    Ankit

  • IPhoto crasht when importing photos and now it doesn't open anymore. Please help!

    I was importing photos in iPhoto, when the program crasht. I tried to restart it, but it never opend. I installed it again and again and made a software update - still doesn't work. What can I do? Please help!

    What version of iPhoto? Assuming 09 or later
    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Rebuild iPhoto Library Database from automatic backup.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. .
    Regards
    TD

  • VLC Downloads fine but doesn't open application. Please help

    Hi
    Can someone please help me with my downloading problem? Excuse me if I sound like a tard but I'm really keen on learning. I searched through previous posts but didn't quite find what I was looking for.
    I download fine. Copy into applications. Everything looks good but it won't kick off. All I get is a flash of the application logo on the dock and then nothing, it disappears. I wanted to download (VLC vlc-0.8.6a.dmg) and Last.Fm (LastFMMac1.1.3.0.dmg) but no dice.
    I have downloaded in the past just fine, but only minor things like Limewire and Quicksilver, they work okay. I'm confused any help would be greatly appreciated.

    Hi ZZ
    vlc-0.8.6a.dmg is for 10.3.9, so that's why it wont open on your OS, which shows your have Mac OS X 10.3.5
    Either find the right one for your OS, or Upgrade to 10.3.9, hardly worth it, just to play the odd video in VLC, but they are your choices.
    I did some hunting for more info for you.
    Why doesn't VLC 0.8.6a work on 10.3, although you state it does?
    "First of all, make sure that you got 10.3.9 installed. Any earlier release, particularly 10.3.5 and below, doesn't support current versions of VLC. Additionally, while QuickTime 6.5.2 is strictly required, QuickTime 7.x is strongly recommended for performance and usability reason"
    So it doesn't look like there is an earlier version.
    If you want to use it, you must upgrade to 10.3.9.
    regards roam
    Message was edited by: roam

  • When I bought my Mac Air OSX Version 10.9.2 my daughter helped me migrate the contents of my previous macbook.  But in the process seems to have duplicated the iTunes library .  The start up disk is almost full and plus it doesn't my iPhone.  Please help!

    When I bought my Mac Air OSX Version 10.9.2 my daughter helped me migrate the contents of my previous macbook.  But in the process seems to have duplicated the iTunes library - How do I get rid of one.  The start up disk is almost full and plus it doesn't synch properly with my iPhone 4S.  Please help!

    Hello nicky:
    You should run repair disk from your software install DVD before you try anything else. The crash may have damaged some of your directories - and a possible cause of the "missing/not missing" tunes.
    Barry

Maybe you are looking for