Forcing a user to only input numbers

Hey guys! I am writing the code for a game of NIM as an assignment. However, i am having trouble in forcing the user to only input certain things, in this case they are only allowed to enter a number that is less than the total ammount of stones in the pile, but greater than 0 (i.e 1 or more). Now this works fine, and if they enter a letter the NumberFormatException catch handles it fine, but what i am having trouble with is when they enter nothing. They just hit return without actually entering a number. This causes they game to accept that as their turn and go to the next players turn. How would i go about forcing the user to input something. Also if you can give me any clues as to how to make this wny more efficent, it would be very much appreciated! Thank you for your time!
               do {
                    if ((userStoneChoice > pileTotal) || (userStoneChoice < 1)) {
                         // if the users choice is greater than the ammount of stones in the pile, force them to enter a new number.
                         System.out
                                   .println("Sorry, but there are "+ pileTotal+ " stones in pile "+ pileNumber+
".Please ensure you choose a number with that range.");
                         userStoneChoice = Integer.parseInt(in.readLine());
                    } else {
               } while ((userStoneChoice > pileTotal) || (userStoneChoice < 1));

    private void doUserMove(){
        try{
            userStoneChoice = getUserStoneChoice();
        }catch(IOException ex){
            ex.printStackTrace();
    private int getUserStoneChoice() throws IOException{
        int choice;
        do{
            choice = 0;
            String str = in.readLine();
            try{
                choice = Integer.parseInt(str);
            }catch( NumberFormatException ex ){}
            if ( choice > pileTotal || choice < 1 ){
                // if the user's choice is greater than the ammount of stones in the pile,
                // force them to enter a new number.
                choice = 0;
                System.out
                        .println("Sorry, but there are "+ pileTotal+ " stones in pile "+ pileNumber+
                        ".Please ensure you choose a number with that range.");
        } while( choice == 0) ;
        return choice;
    }

Similar Messages

  • Forcing a user to only select from Parameter LOV list

    Hi,
    I suspect that the answer is no but I'd appreciate clarification on the matter. I am wondering if there is any way to prevent a user entering a value into a parameter field - I want them to only select from the parameter's drop down LOV list. This will apply to Discoverer Viewer but would like to know if it could be done for Plus ( or not ) as well,
    Kevin.

    Hi Kevin
    Try changing the item class property called Require user to always search for values.
    According to my notes: This is unchecked by default. If you check this, Discoverer will launch the Search dialog box whenever a user clicks on the list of values. Should you have a large list of values, you may want to consider turning on this optionto making the LOV box pop up automatically.
    I am not convinced this will make the pop-up come up but it's worth a try.
    I'd be interested in hearing how you get on.
    Best wishes
    Michael

  • Force user to give input on only F4 help

    Hi,
    I have two screen fields.Based on what data is entered on first field, F4 options for second field should be filtered.
    Also,user should give input to both the fields only by using F4 functionality, not by keyboard input.
    This is a module pool screen, not a selection screen.
    Presently I have used F4IF_INT_TABLE_VALUE_REQUEST in Process on value request block to give F4 help on both the fields.
    I can make the user to give input on only dropdown by  changing the dropdown to List box in screen painter,but then, POV block and hence the above FM is not getting triggered.
    I can't assign search help or check tables in both cases because the input options  are dependent on previous inputs.
    Please help.

    Hi Kiran,
    Make both the fileds as list box and create a module for bot the fields.
    PROCESS ON VALUE-REQUEST.
      FIELD 'FIELD 1' MODULE field1_values.
      FIELD 'FIELD 2' MODULE field2_values.
    Inside the module fetch the values into an internal table depending upon your requirement and pass the internal table to FM - F4IF_INT_TABLE_VALUE_REQUEST. For the second field the values sholuld be fetched into the internal table based on the values of the first field.
    Thanx & Rgds,
    Krishna

  • Report that Forces a User to Input a Date Range

    Greetings,
    I am generating a work times report and would like to force the user to select a date range when the report first opens. This would pull only the data for the specified range from my database.
    I prefer drop down lists or calendars, but am wondering if this is possible.
    I guess one other important element is that I would like to "dumb down" the interface, so the user of the report does not have access to all of the features of the program.  Basically I only want them to have read privileges.
    I'm new to CR, so would appreciate any guidance.
    Thanks
    Peter

    Here is what the Help system has to say about the read only feature:
    You can make a report, section, area, or object read-only so it can't be formatted.
    When you set this option, choices in the Format Editor become inactive.
    The formatting options that are usually available on the toolbars or shortcut menus are also suppressed for the report or object.
    Note:    This feature is for your convenience in protecting report formatting; it is not intended to be used as report security.
    Also, if you want the user to be prompted for parameter values each time they open the report, take the check mark out of the
    "Save Data with Report" option.
    Jason

  • System.read.in(); -problems when inputting numbers

    Very wet behind the ears when it comes to java and having problems in inputting numbers. My course requires me to write a program that converts degrees c to degrees f. An addition is to have the user input the value of degrees c. When I input a value, say 0, then instead of c being that value it is 49 instead (maybe ASCII?). I sense that the problem is the System.in.read(); bit. I've preceded it with (int) and also tried (char) but to no avail. The other problem is how to get the program to accept a double figure or treble figure input (i.e 20 degrees c). My program is below. Any advice would be greatly appreciated.
    //This program is designed to convert degrees Celsius into degrees Fahrenheit
    class Ctof
         public static void main(String[]args)
         throws java.io.IOException
              //identify variables
              int c;
              double f; //double is needed as calculation involves fractions
              System.out.println("Please input a value of degrees Celsius then press [Enter]");
              c=(int)System.in.read();
              f=(c/(5.0/9.0))+32;
              System.out.println(c + " degrees Celsius"); //prints value of c
              System.out.println("This is " + f + " degrees Fahrenheit"); //prints value of f
    }

    I think this should work...
    import java.io.*;
    class Ctof
    static BufferedReader b;
    public static void main(String[]args)
    throws java.io.IOException
    //identify variables
    int c;
    double f; //double is needed as calculation involves fractions
    b = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Please input a value of degrees Celsius then press [Enter]");
    c = Integer.parseInt(b.readLine());
    f=(c/(5.0/9.0))+32;
    System.out.println(c + " degrees Celsius"); //prints value of c
    System.out.println("This is " + f + " degrees Fahrenheit"); //prints value of f
    } I've added a BufferedReader to read data from the input stream (System.in). This then gets converted to an int. System.in.read() is only really for reading bytes.
    Andrew

  • I created a form with Single Choice fields, 4 days with times listed. But, I want the user to only be able to choose one time, and the time chosen to be unavailable for other users. How do I do this?

    I created a form with Single Choice fields, 4 days with times listed. But, I want the user to only be able to choose one time, and the time chosen to be unavailable for other users. How do I do this? I have 4 blocks of Single Choice fields in order for the summary page to give me each day in the final report. But, I need the user to be able to make a selection of any day and time and that apointment to no longer be available to future users when they log in. Plus, when the user clicks on the time, they are unable to change their mind and choose another time. Here's the link if you want to see what I'm talking about: 2015-2016 Workload Apportionment Review

    I'm afraid not.    It's not rocket science but you need to do some coding. 
    You'll need to find a script (php) and save it to your local site folder.  Then reference the script in your form's action attribute like so.
         <form action="path/form-to-email-script.php" >
    The input fields in your HTML form need to exactly match the script variables. 
    I'm  assuming you're hosted on a Linux server which uses PHP code.  Linux servers are also case sensitive, so upper case names are not the same as lower case names.  It's usually best to use all lower case names in your form and script to avoid confusion.
    Related Links:
    Formm@ailer PHP from DB Masters
    http://dbmasters.net/index.php?id=4
    Tectite
    http://www.tectite.com/formmailpage.php
    If this is all a bit beyond your skill set, look at:
    Wufoo.com (on-line form service)
    http://wufoo.com/
    Nancy O.

  • How do it force a user to enter a time in a date time field??

    I am new to live cycle, not to acrobat pro. I must say live cycle is pretty cool and i may just switch to live cycle forever...
    But i can not figure this out. I have a HR form. I need to make the time of occurence field, required, validate and wont let you move on until you enter a time.
    Right now it functions as required, it shows a custom message, but the user can enter garbage text and skip through. How do i set up this field where the user can only enter a time and not skip through??
    I am sure this is rather easy, i just dont know where to start.. Thanks in Advance

    Hi Paul:
    That completely makes sense... Only problem what would or could the javascript be??
    I have already inserted some for the save as and print buttons sucessfully
    BTW in my form the time/date field is selected and to format to show time only. In my other date fields is does show a calendar after you hit the little arrow and the user can still insert garbage.
    What i would ultimately want is for the user not to insert garbage and forcing them to insert a time in the time field.
    It is possible that i forgot or missed a step being as im new to Live Cycle.

  • Forcing end user to open the child form in the resource request dataset

    Hi,
    Is there any way where we can force end user to open the child form of a resource request dataset and enter the values for the attributes in the child form. The child form attribute is mandatory. However, currently, OIM allows user to submit the request without opening the child form and to enter values for child form attributes(which is mandatory).
    Thanks.

    Child dataset attributes are set to required="true". But it will come into picture only if end user opens the child form. If he forgets to open the child form, still he is able to submit request without entering values to the attibutes(whose required=true) in the child form. OIM is alowing to submit request if he doesn't open the child form.
    I hope i was able to put it in corrrect way.
    Thanks.

  • Forcing a user's password to be expired

    I am trying to test my customized change password page. I have updated the URL in the LS_CONFIGURATION table. How can I force a user to produce the change password page so I can test my customized change password page?

    Also, is there a way to force the user's password to expire upon first successful login and likely force the user to change the pre-assigned password? This is a requirement on the customer's wishlist.
    Chris, please let us all know if you get an anwer to your question. I can't be the only person who'd be interested.
    Mike

  • How to Make JTextField Accept Only Specific Numbers?

    Hello There
    I've made 3 JTexfields That accepts only Numbers
    But I Want To Make Them Accpets Numbers only from 1 to 12
    and if the number is greater than 12 they don't accept it?
    another Thing That I've Set Their Columns To 2 meaning that i want the user to enter only two numbers
    but yet the user can enter many numbers how would i restrict entering numbers to only two numbers?
    here's my code:
      import java.awt.*;
      import javax.swing.*;
      import javax.swing.text.*;
      public class ManyText extends JFrame{
           public static void main(String[]args){
           JTextField[ ] text = new JTextField[3];
           JButton button=new JButton("Press");
        for(int i = 0; i < text.length; i++)
         text[i] = new JTextField(3);
         for(int i = 0; i < text.length; i++){
         text.setColumns(2);     
    text[i].setDocument(new PlainDocument(){
    public void insertString(int offs, String str,
    AttributeSet a) throws BadLocationException{
    if("0123456789".indexOf(str) < 0)
    java.awt.Toolkit.getDefaultToolkit().beep();
    return;
    super.insertString(offs, str, a);
         JFrame f=new JFrame();
         f.setSize(200,200);
         f.setLayout(new FlowLayout());
         f.add(text[0]);
    f.add(text[1]);
    f.add(text[2]);     
         f.setVisible(true);     

    ejp wrote:
    Actually I would suggest you're using the wrong control. I would use a JComboBox or a JSpinner for this.I suggested he use a JSpinner 1-2 threads ago. Maybe if he hears it enough, he'll believe it.

  • How to deliver MM02 to user with only Bin Location editable.

    My user wishes to have access to change only the Bin Location field in MM02. How can we achieve this? or in other words how can we deliver MM02 to user with only the Bin Location field editable.
    My basis guy sees a possibility if we can some how provide the authorization objects of all the fields of MM02.Shall that be a practical approach. if yes, what is the way of finding the authorization objects?
    Regards,
    Alok.

    Hi,
    You can create a transaction variant in SHD0 for MM02.
    [Transaction variants|http://help.sap.com/saphelp_nw70/helpdata/en/7d/f639f8015111d396480000e82de14a/content.htm] simplify transaction flow by:
    -Inserting default values in fields
    -Hiding and changing the ready for input status of fields
    -Hiding and changing the attributes of table control columns
    -Hiding individual menu functions
    -Hiding entire screens
    Transaction variants are actually made up of a series of screen variants. The field values and field attributes for each screen in a transaction variant are stored in screen variants. Each variant is assigned to a transaction. Variants may, however, contain values for screens in multiple transactions, if transaction flow makes this necessary. The transaction the variant is assigned to serves as its initial transaction, whenever you start the variant.
    Both client-specific and cross-client transaction variants exist. Screen variants are always cross-client; they may, however, be assigned to a client-specific transaction.
    A specific namespace has been designated for cross-client transaction variants and screen variants and they are both automatically attached to the Change and Transport System. Client-specific transaction variants can be transported manually.
    Transaction and screen variants may be created for all dialog and reporting transactions. However, there are certain restrictions that apply to their use, depending on how their corresponding transactions have been realized internally.
    Transaction variants may not be created for transactions already containing pre-defined parameters (parameter transactions and variant transactions).
    The following sections contain additional information on how to create and maintain transaction variants:
    Maintenance
    Additional Functions
    Transport
    Regards,
    Srilatha.

  • JAVA CODE Restricting users from entering Fractional numbers in Data forms

    Hi,
    is there anyone who can help me with the Java Script code of ValidateData.js file?? I am very novice in scripting and find it very difficult to write a proper javascript code to restrict the users from entering fractional numbers to HEADCOUNT cell. I would very much appreciate if i get some help from anyone out there.
    Users should be able to only enter whole numbers to the cells for Headcount entry.
    Kindly give me the layout of the script to be used. Has anyone out there ever done anything like this??
    Looking forward for a help.
    Thanks.

    Hi,
    I think customCellEnterPre and customCellValidatePre is the function you'd be using
    http://download.oracle.com/docs/cd/E17236_01/epm.1112/hp_admin/apas02s01.html
    http://download.oracle.com/docs/cd/E17236_01/epm.1112/hp_admin/apas02s03.html
    http://download.oracle.com/docs/cd/E17236_01/epm.1112/hp_admin/apa.html
    You can refer to SampleValidateData.js that's within Planning deployment custom js folder for further reference and sample usage.
    Cheers,
    Alp

  • Force a user event

    Hi,
    In a point of my vi I want to force a user event in order to enter in
    an event case in run time. I want to simulate an event over a
    multicolumn listbox, for example, Double Click.
    How can I do it? Some example?
    I am working with Create user event, generate user event and destroy user event but I don't know how it works.
    Thanks very much,
    ToNi.

    tonitpp wrote:
    Sorry, the object over I want to force an event is a button and not a multicolumn listbox. It works but.... when I force a Double Click event over that button the user can see how the button is pressed automatically and I don't want the user see it, I would like to do it transparent to the user. I use a value (signaling) property node and I associate to it a true value. Another way to do it?
    The event also gets triggered if you wire a FALSE to the Signaling property. It does not matter if the value actually changes, only that the signaling property is written to trigger the event. Try it!
    LabVIEW Champion . Do more with less code and in less time .

  • How do i put a loop round this so the user can only enter a number between

    how do i put a loop round this so that the user can only enter a number between 1 and 3 if a number like 4 is enter it will just say something like retry
    if (CA.trim().equals(ans1)){
    Out = "incorrect";
    else if(CA.trim().equals(ans2)){
    Out = "incorrect";
    else if(CA.trim().equals(ans3)){
    Out = "correct";
    else{
    System.out.println("Enter 1 2 or 3 try doin test again");
    System.out.println(Out);
    byte b[] = Out.getBytes();
    out1.write(b);

    You already know the conditions so here's some pseudocode.
    get input
    while(input is not what I want (between one and three))
            Inform user of improper input and ask for it again
            get new input

  • Recovery Manger backup not restoring user documents only public

    I had a problem after a Windows Update on 14/02/15 - my laptop refuse to reboot, instead it sat with "Restarting Windows" for about 8 hours before I resorted to power down and restart.
    It got worse from then on in...the laptop then refused to boot, kept going to to the Recovery Manager, but every option resultedin returning to the same page. Tried to use MS System Restore from within recovery manager bu it told me there were no system restore points. 
    I tried everything, but always vame back to Recovery has encountered an error, or no changes can be made, and still couldn't boot. So I used the Reset my files option and created a backup data set to a USB drive.
    The reset option didn't work either - it only got me as far as the Windows logon screen and only listed administrator as a user, not my normal user accont.
    Clicking on the administrator account and entering a password or even no password resulted in the message your administrator account has been disabled contact system admin.
    I googled account recovery info, tried to enable the admin account using cmd but still no good - So I did I full recovery fresh install and proceeded to install all HP and Windows updates (except the 14/02/15 one)
    I created my user accont using my MS credentials as before, then once everything was setup proceeded to use the Restore file from the USB backup. I had expected the backup to restore the items to their original locations, however this wasn't the case they are restored to new folder, but still in a directory tree so not too bad.
    I was then horrified to find that whilst the backup file list showed all of the documents, images etc in my user account the files that are restored do not include the documents and images from my user account, only the public documents.
    In the found file list of the backup, it lists my user account folder as found.000\my documents etc. when you explore the individual swm backup files - within them are the original files, unnamed and no file extensions so restoring them and adding file extensions manually for over 10,000 documents would be a nightmare.
    Has anyone experienced the same issue - all I wanted was my document files to be restored and thought that using the Recovery Manager software to create what it told me was a successful backup would have achieved this. Especially as the found file list shows the docs I need.
    So in a nutshell I have an apparently successful backup archive, that doesn't want to restore named user account documents...any ideas would be appreciated.

    @MarkW-UK 
    ‎Thank you for using HP Support Forum. I have brought your issue to the appropriate team within HP. They will likely request information from you in order to look up your case details or product serial number. Please look for a private message from an identified HP contact. Additionally, keep in mind not to publicly post ( serial numbers and case details).
    If you are unfamiliar with the Forum's private messaging please click here to learn more.
    Thank you,
    Omar
    I Work for HP

Maybe you are looking for

  • HP LaserJet 3015 not printing with 10.5.6

    I just upgraded from 10.5.5 to 10.5.6 and my HP Laserjet does not print. I removed it and added it back but when I try to print it always gives me the following error when the printer queue is trying to connect: Printer busy (status:0xe00002e9) Pleas

  • Bapi or FM to post a FI document

    Hi experts, I am looking for a standard BAPI or FM to check/post a PARKED FI document. I know already BAPI_ACC_INVOICE_RECEIPT_POST but it creates a document from scrach. I need one that changes the status of an existing parked document   I need a BA

  • Deploying JAXRPC service on NON-JWSDP Tomcat

    Hi, I saw a similar question earlier, but not an answer.. I'm in a situation where I want to deploy a JAXRPC service on a Tomcat 4.1.12. I use the JSWDP kit from Sun to develop and test, and then I would like to be able to package my service as a .wa

  • Bookmarks bar and tab controls not working in mobile Safari on iPad2

    The bookmarks bar as well as tab controls in Mobile Safari on iPad 2 are not clickable. Only the topmost nav buttons work. This persists through reboots w/Safari closed via mem manager, and a system restore. What do?

  • Show INSTALLED bundles (not just associated....)

    Is there a way to list/show the bundles that have actually been installed on a device? This is as opposed to what is associated with a device, which is what "zac bl" shows. I see that "zac bl --all" lists all associated bundles (including filtered) h