Help me solve the "ANSWER" problem.

Hello, im new here, and im a new java student.
i've written a program. however, the program asks the user a question, the user needs to answer either 1 or 2. i need the program to ask the question as long as the user doesnt enter 1 or 2. so if the user enters "2365" or "addasda" it will ask the question again.
this is the main class:
import java.util.Random;
public class Game
     private String name;
     private String answer;
     private int numMarbles;
     private int marblesTaken;
     private int pcMarblesTaken;
     int exit;
     int exit2;
     public Game(String name)
          this.name = name;
     public String getName()
          return name;
     public boolean goodInput()
          //do
          //     if(exit==1)
          //          return true;
               if(exit2 == 1 || exit2==2)
                    return true;
                    return false;
          //while(!goodInput());
}This is the test class:
import java.util.Random;
import java.util.Scanner;
public class GameTester
     public static void main (String [] args)
          Scanner input = new Scanner(System.in);
          int exit;
          do
               System.out.print("what is your name: ");
               String name = input.next();
               Game howdy = new Game(name);          
               int exit2;
               do
                    System.out.println("Hello " + howdy.getName() + " Do you want to go first? (1)Yes, (2)No");
                    exit2 = input.nextInt();
               while(howdy.goodInput());
               System.out.println("You must enter either 1 for Yes or 2 for No");
                    if(exit2==1)
                         Random random = new Random();
                         int min = 10;
                         int max = 100;
                         int diff = max - min + 1;
                         int numMarbles = random.nextInt(diff) + min;
                         System.out.println("the number of marbles is: " + numMarbles);
                         while(numMarbles > 1)
                              System.out.print("How many marbles you want to remove? ");
                              int marblesTaken = input.nextInt();
                              numMarbles = numMarbles - marblesTaken;
                              System.out.println("the number of marbles left is " + numMarbles);
                              System.out.println("It is now the computer's turn");
                              int pcMarblesTaken = random.nextInt(numMarbles/2)+1;
                              System.out.println("the computer has taken " + pcMarblesTaken + " marbles");
                              numMarbles = numMarbles - pcMarblesTaken;
                              System.out.println("the number of marbles left is: " + numMarbles);
                              if (numMarbles==1)
                                   System.out.println(howdy.getName()+ " You lose");
                                   break;
                              System.out.println("It is now your turn");               
                    else
                         Random random = new Random();
                         int min = 10;
                         int max = 100;
                         int diff = max - min + 1;
                         int numMarbles = random.nextInt(diff) + min;
                         System.out.println("the number of marbles is: " + numMarbles);
                         while(numMarbles > 1)
                              int pcMarblesTaken = random.nextInt(numMarbles/2)+1;
                              System.out.println("the computer has taken " + pcMarblesTaken + " marbles");
                              numMarbles = numMarbles - pcMarblesTaken;
                              System.out.println("the number of marbles left is: " + numMarbles);
                              System.out.println("It is now your turn");
                              System.out.print("How many marbles you want to remove? ");
                              int marblesTaken = input.nextInt();
                              numMarbles = numMarbles - marblesTaken;
                              System.out.println("the number of marbles left is " + numMarbles);
                              if (numMarbles==1)
                                   System.out.println(howdy.getName()+" You Win!!");
                                   break;
                              System.out.println("It is now the computer's turn");
          System.out.print("Do you want to play again? (1)Yes, (2)No ");
          exit = input.nextInt();          
          while(exit==1);
          System.out.println("Thanks for playing with us!");               
}     

The question is.
How do i make the program ask the question
System.out.println("Hello " + howdy.getName() + " Do you want to go first? (1)Yes, (2)No");as long as the user enters the correct answer.
so if they enter "adsdds" or "45" it will repeat the question again.

Similar Messages

  • I need help to solve the following problem

    EMPLOYEES with coulmns
    employee_id number, first_name varchar2(50), last_name varchar2(50), salary number, deptno number, manager number, date_of_join date, date_of_birth date.
    DEPARTMENT with columns
    deptno number, dept_name varchar2(100),location varchar2(100);
    --Proper exceptions should be handled in all procedures and functions
    7. Create a package "Salary_revision" as per steps given below.
    1. Write a function "Update_salary" in the package that accepts two parameters
    "Employee_id" and "Sal_raise"-Number, return type should be Number.
    · Function "Update_salary" should be an AUTONOMOUS TRANSACTION function.
    · The function should accept the employee id and the amount of salary to be raised.
    · There should be an update statement which will update the employee table for each
    employee id with the current salary + salary to be raised.
    After updating the employee table with the new salary , function should return the new salary back.
    Q8. Write a PL/SQL block which will fetch all employee id and their salary into a pl/sql table from the employees table .
    1. The Pl/sql table should have two columns to hold the employee id and salary
    2. Loop through the pl/sql table (before starting the loop, a check condition should be provided to see if the pl/sql table is empty.
    3. For each record in the pl/sql table loop, call the function "Update_salary" from the package "Salary_revision" created in "Question 7" .
    4. Pass the values for parameter “employee_id” and “Sal_raise”.
    Value for employee id should be the value fetched from pl/sql table
    For parameter "sal_raise" , pass value based on the formula given below
    Pass 10% of current salary if the current salary is greater than 20lakhs.
    Pass 15% of salary if the current salary is greater than 15 lakhs and less than 20 lakhs.
    Pass 18% of salary if current salary is greater than 10 lakhs and less than 15 lakhs.
    Pass 20% of salary if current salary is less than 10 Lakhs.
    5. The new salary returned should be displayed along with Employee last name and first name (use DMS_out.put_line)
    Q9. Create a package Employee_lib with functions as given below.
    1. Create a Function get_emp_doj_dept that will accept the employee id and return his date of join and department number, both these values should be returned together in a record type variable.
    2. Create another function get_emp_doj that will accept the employee id and department number as parameter. The function should fetch only his date of join and return the same. (Appropriate return type variable should be declared).
    3. Create a function get_emp_birthday that will accept department number as parameter.
    The first name and last name of all the employees whose birth day falls on the
    system date should be populated in a PL/SQL table. (Declare this pl/sql table in the package specification). Function “Get_emp_birthday” should return the count of employees fetched.
    Q10. Create a package Employee_lib_overload functions as geiven below.
    1. Create one function "get_emp_doj_bday". This function should be overloaded to handle the functionality of all 3 functions get_emp_doj_dept" , "get_emp_doj" and "get_emp_birthday" created in question #9.
    * If the user calls the function "get_emp_doj_bday" with only employee id as parameter, then it should perform the same functionality of function "get_emp_doj_dept" as in question #9.
    * If the user calls the function "get_emp_doj_bday" with employee id and department number as parameter, then the function should perform the same functionality of "get_emp_doj" as in question #9.
    * If the user calls the function "get_emp_doj_bday" with department number as parameter then it should perform the same functionality of function "get_emp_birthday" as in question #9.

    This is not a homework solving forum. Do your own work and get back here if you have any specific problem.

  • Hello. the last month i face a problem with youtube at my macbook. most videos stop playing after maybe 20 - 25 sec. the same time the time bar stops moving. could you help me solve the problem? thank you

    hello. the last month i face a problem with youtube at my macbook. most videos stop playing after maybe 20 - 25 sec. the same time the time bar stops moving. could you help me solve the problem? thank you

    hello. the last month i face a problem with youtube at my macbook. most videos stop playing after maybe 20 - 25 sec. the same time the time bar stops moving. could you help me solve the problem? thank you

  • When importing clips to iMovie11 the audio is missing. I have been able to successfully to this in the past and all of the sudden it is not working. Any help to solve the problem would be appreciated.

    When importing clips to iMovie11 the audio is missing. I have been able to successfully to this in the past and all of the sudden it is not working. Any help to solve the problem would be appreciated.
    Thank you for your help!

    Download/install an app is a know possible solution.
    3. Install another app from the App Store
    If all user-installed apps are not launching, it could be an Apple ID authorization issue. Download and install an app that isn't already installed on your device to reset this information.
    Note: If you have installed apps using multiple Apple ID accounts, you may need to perform this step for each account.
    Above from Apple's :
    iOS: Troubleshooting applications purchased from the App Store

  • HT3702 please help to solve the violation from itunes

    please help to solve the violation from itunes

    Sorry, but the minimal amount of information you have provided does not allow us to understand what problem you are having. You will need to post a more complete description of your issue before anyone can even guess at suggestions.
    Regards.

  • HI ,We would like to ask you to help us with the following problem

    We would like to ask you to help us with the following problem. As usual we tried to post unmatched received advance payment which is subject to output VAT via transaction SM35. Normally we post the payment to account 501020 (Advances Received from Operating Activities), we generate output VAT by clicking on u201CSimulate Taxu201D. Then we simulate the document and four lines are automatically generated (please see the attached scan of such document posted recently):
    40           510000 (Trade Receivables - Receive from Bank)
    19           501020 (Advances Received from Operating Activities)
    50           400000 (Output Tax (Sales Tax Payable))
    40           405033 (Customer Advances VAT)
    However when we tried to post it today it is not possible and an error message u201CTax clearing account 405033 may not have open item managementu201D appears u2013 please see the scanned printscreen. This did not happen in the past.
    We would appreciate if you could solve it as soon as possible as we still need to post it to period 12.

    Hello
    You execute the t/code FS00 for G/l 405033 and go the control tab select tick in open item mgt under act mgt in co.code.
    Regards
    Avijit

  • I bought iphone 4 in US and i and other person not able to listen properly because on the time of conversation voice cracking and difficult to understand each others.so i would like to request you that please solve the above problem.i love my iphone.

    Sir,
    I bought iphone 4 in US.last 6 month me and other person not able to listen properly the voice because the voice is cracking.i have called earlier about the above problem and they said to upload the new verson 6.1.3 and it will be done but after loading this version still i am facing the same problem.so ,i would like to request you that please solve the above problem as soon as you can.I will be thankful to you.i love my apple Iphone.
    waiting for your earliest reply.
    thanks
    Rajeev Gupta

    Hello sir
    As you know about my iPhone 4 which has a problem of voice cracking so I would like to replace to other phone like IPhone 5s.I will pay the replacement charges immediately.i am reaching miami on 19th of janvary 2014 so I would like to request you please arrange my appointment on the Apple store,dadeland mall ,miami at 15.00pm as I will reach miami at 13.00pm and my flight to India at 19.00pm.
    Last time you told to replace at miami on 26th of September but without oppoimtment they have not entertained me.so I would like to request you that please arrange my appointment this time
    I will be thankful to you
    Rajeev Gupta

  • How do I solve the memory problem ( 5 beeps ) upon startup?

    hp compaq d530SFF,  how do I solve the memory problem (5 beeps ) upon start up?

    Hi:
    You already know the answer to that! 
    http://h30434.www3.hp.com/t5/Desktop-Lockups-Freezes-Hangs/when-I-try-to-boot-up-lighs-flash-red-and...
    Paul

  • Will the next IOS update 5.0.2 solve the batter problem of my iphone 4s?

    will the next IOS update 5.0.2 solve the batter problem of my iphone 4s?

    Let me check my Magic Eight Ball..... All signs point to "Yes"
    All kidding aside, We all hope so!!

  • How to solve the setColor() problem with multithreading?

    My fractal program uses a custom number of threads to draw the complete image. If I use just 1 thread, the image looks clean, if I use more threads some pixels of the image gets other colors. The problem ist the painting code:
    g2d.setColor(col);
    g2d.drawLine(x, y, x, y);as it is necessary to first set the color of the graphics object and then draw the line. I can solve this pixel color problem by synchronizing the Graphics2D object:
    synchronized (g2d) {
      g2d.setColor(col);
      g2d.drawLine(x, y, x, y);
    }but this slows the code down to times where just 1 thread is calculating the image. Unfortunately, I can't find a draw() method that has a color parameter.
    I tried to divide the panel into multiple BufferedImages (1 for each thread) which solves the pixel problem but only the first BufferedImage get's drawn.

    I solved my problem now. My solution is to use a separate BufferedImage for each Thread. I still had a bug where i didn't transformed the x/y coordinates of the complete image to the shifted x/y coordinates of the single BufferedImages, so that the threads draw the image out of the visible area which looked like all threads after the first only had a black image. After adjusting teh coordinates, the fractal now gets drawn correctly. And boy it's much faster with multiple threads - even on single core systems. On a dual core system, using 10-20 threads about doubles the performance as both cores have work almost all the time until the fractal is finished. :-)

  • When apple will solve the wifi problem ?

    when apple will solve the wifi problem ?

    They keep trying, but haven't yet in all the time OS X has existed. Every version of OS X has had some WiFi issue with some group of users. The normal pattern is they release a fix for one group, and another group develops a new WiFi problem.

  • Can anyone help me solve the problem of text displaying very rough on my new ASUS PA279Q display monitor running off my MacBook Pro?

    This is regarding a brand new ASUS PA 279Q, 2560 x 1440 IPS monitor. I'm connected via mini display port (into thunderbolt port on MacBook Pro) to display port on ASUS monitor; using cable ASUS included with the monitor. Mid 2012 MacBook Pro…full specs at bottom of this post.
    I have resolution set at 2560 x 1440 which is the native resolution according to the ASUS spec. I tried the other resolutions available in my System Preferences and text displayed rough with those settings too. I've tried adjusting contrast, brightness and sharpness via the ASUS control panel and didn't solve the problem. Also tried calibrating via Mac's system preferences/display and that did not improve text display either. All the text on this monitor (no matter what software I launch, Finder, InDesign, Illustrator, MS Word, Excel, VMWare Windows XP, Windows versions of Word, Excel, Acrobat, etc, all are consistently rendering text the same way ---  ROUGH and with "HALOS" around each letter.
    All point sizes of text and at various scales, display very rough on the screen. (My comparison is the retina display of my MBP and a Thunderbolt…so those two displays are my expectations.) I'm using the same MBP for both a Thunderbolt display (at work) and this ASUS at my home office.
    On the ASUS it's not as noticeable when the text is on white backgrounds, but I'm a graphic designer and compose images with text all day everyday. Not to mention the specs on this ASUS PA279Q indicate it's built for the professional so I would expect better text rendering. I haven't even addressed color calibration and balance yet, because that won't matter to me if the text won't display any better than it is now.
    I was so hopeful after researching all the specs on this monitor it would be a viable alternative to the glossy display of the Thunderbolt display. (Which, I do love the Thunderbolt display for it's clarity and how it displays crisp, clean text at all sizes. (This ASUS actually displays text decently if I increase the text so each letter is about 4" high. Which is pointless for practical purposes -- that'd be like doing page layout through a microscope!)
    I kept holding off on getting a monitor for the home office thinking the Thunderbolt would be updated soon. I'd be sick if I dropped a grand on piece of 2011 technology only to learn a few days later an updated Thunderbolt display hit the market! Not to mention, I'm praying Apple comes out with a less reflective Thunderbolt display. The glare and reflection is the main reason I looked elsewhere for a large monitor; hence my asking for help. Hoping the ASUS text display issue can be worked out. My expectation is for it to display like the MBP retina and Thunderbolt display text. That possible?
    Alternatively, I guess I could do the Apple Refurb Thunderbolt at $799. And see if there's a decent aftermarket anti-glare I could stick on it?
    Thanks for reading my post. Hope someone can help; offer any suggestions? Words or wisdom?
    Has anyone else had similar issues and figured out a resolution? Help!
    MacBook Pro
    Retina, Mid 2012, 2.3 Ghz Intel i7
    8GB 1600 MHz DDR3
    OS X 10.8.5
    NVIDIA GeForce GT 650M 1024 MB
    ASUS PA279Q

    I uninstalled those two items. It still runs slow on start-up and when opening safari, firefox, iphoto, itunes, etc. It's not snappy like it used to be. Any other ideas? Thanks.

  • TS1398 I can't access to the web pages thro' Wi-Fi, after switching on the wi-fi.But if I switch off the iphone andswitch on the phone then I can get the web pages.Daily I have to repeat this process to access the web pages.help to solve the problem.

    I can't access the web pages thro' wi-fi,But if I switch off the phone and thenswitch on the phone again I am able to access the web pages.Daily I have to repeat this process.help to solve this problem.

    Does using 192.168.1.1 get you to the web page?
    Firmware Update Process
    To safely update FW, I recommend doing the following: Download the FW file from the support site first.
    Disable the auto update feature on the router.
    1. Save router config to file first using IE or FF with all security add-ons disabled.
    2. Factory reset the router with all other devices disconnected or turned OFF accept for 1 wired PC.
    http://kb.linksys.com/Linksys/ukp.aspx?pid=80&app=vw&vw=1&login=1&json=1&docid=9d2ff02077f645679972a...
    3. Reload or Update the FW using IE or FF. Just download the FW file to your local wired LAN PC.
    http://kb.linksys.com/Linksys/ukp.aspx?pid=80&app=vw&vw=1&login=1&json=1&docid=0a6881b90224439b92c8d...
    4. Factory reset the router and then set up from scratch first using the local log in link and test with out loading the saved config from file. Check to see if any problems are fixed before loading the saved config from file. Sometimes you need to set up from scratch with out loading the saved config file. Just safer that way.
    PC Web Browser Configurations
    What browser are you using?
    If IE 8, 9, 10 or 11, set compatibility mode and test again.
    Disable any security browser Add-ons like No Script and Ad-Block or configure them to allow All Pages when connected to the router.
    Clear all browser caches.
    Be sure to log into the local log-in account on the router first.

  • My imac stops(freezes) everytime when I try to extract ipod nano. So if I quit the connection by force, it stops again. Have no choice but to shut down the imac pushing power supply button. Pls help me solve out this problems.

    My imac stops everytime when I try to extract ipod nano. So if I do it by force it freezes agian. Have no choice but to shut down the computer
    by pushing power button. Pleas help me solve this out!!!
    It's not good to shut off the power forcibly, right? (I dun know what else I can do...)

    Hi Min! I'm having exactly the same issue - have been putting up with it now for months but have finally had enough! Every single time i eject either my iphone, ipad or ipod nano, itunes freezes up, the computer becomes unresponsive. Usually i can use the mouse to highlight icons but the system doesn't respond, the keyboard doesn't work and I have to do a hard reset.
    Arrrrrggggggh!!!!!!! lol
    Someone please help!!!

  • To solve the sound problem

    i have problem in my computer ,cause this get very slow after open 2 or 3 works

    Hi RashisR,
    Welcome to the HP Forums!
    I would like to take a moment and thank you for using the forum, it is a great place to find answers. For you to have the best experience in the HP forum, I would like to direct your attention to the HP Forums Guide First Time Here? Learn How to Post and More.
    I am unsure if you are having an issue with your sound or your computer's performance is slow.
    Here is a link to Using Automated Troubleshooting (Windows 8).
    Please select the the correct option and follow the on screen prompts.
    There is  a link on the document for troubleshooting hardware and sound  windows 8.
    I am also including this document . Improving System Performance without Adding Memory (Windows 8).
    If you would like further assistance, please provide your exact model of HP computer and the results from any troubleshooting steps you have done. Please also confirm what Operating System you are running.
    How Do I Find My Model Number or Product Number
    Sparkles1
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos, Thumbs Up" on the bottom right to say “Thanks” for helping!

Maybe you are looking for

  • Photo Library taking too much space

    my photo library is currently taking up 361 mb with 0 photos or videos in it. I wanted to be able to download some apps so im wondering how i can clear this space seeing that there is nothing that should be taking it up. I have a 8gb iphone 4s ios 8

  • Help regarding Workflow

    Hi, We have two custom fields (*Department* and Service Engineer) on our service request page. I have created a workflow that triggers when modified record is saved. The condition when it should trigger is : IF Department = XYZ AND Service Engineer =

  • Best Practices for user ORACLE

    Hello, I have few linux servers with user ORACLE. All the DBAs in the team connecting and working on the servers as ORACLE user and they dont have sperate account. I create for each DBA its own account and would like them to use it. The problem is th

  • Canon software update 2.4.1 - canon mp830

    when i installed the driver update onto my printer, it suddenly stopped wanting to print word documents... if this is the right forum, has anyone else had this problem?

  • EditingUtils.js script warning

    I am using DWCS3 and just started getting the following error when opening files: A script in file c:\[filepath]\Adobe Dreamweaver CS3\configuration\shared\spry\designTime\EditingUtils.js has been running for a long time. Do you want to continue? Bef