LAST QUESTION ABOUT MY CODE (promise)

Here is my final code for the 6/49 lottery game (it's a more simplified version so don't mind that there is no Bonus Number) sorry for the long code...
I'll just post my question here for those who don't want to go through all of this.
I want to throw an exception and let it catch it after the first input box appears. So let's say I entered text or a null value in the first input box then it would loop back to the beginning of the program and output a message saying "You entered a wrong value!"
But in the code that I have, even if I enter text or just press enter without inputting anything, it just moves on to the next input box, until on the 6th input box it says "invalid value".
So how would I proceed in doing this?
THANKS!
import java.util.Random;
import javax.swing.*;
public class Game
     public static void main (String args[])     
          mGame();
     }//end main
     public static void mGame()
          JOptionPane.showMessageDialog(null, "Ali Uz\n110231263", "About", JOptionPane.PLAIN_MESSAGE);
          Random randomNumbers = new Random();
          String sInput,
                  win = "";
          int iNumber1=0,
               iNumber2=0,
               iNumber3=0,
               iNumber4=0,
               iNumber5=0,
               iNumber6=0,
               match=0,
               randNumber,
               prize=0;
         int array [] = new int [50];
          try
                    //get the numbers from the user
                    sInput=JOptionPane.showInputDialog ("Enter winning number 1.");
                    sInput=JOptionPane.showInputDialog ("Enter winning number 2.");
                    sInput=JOptionPane.showInputDialog ("Enter winning number 3.");
                    sInput=JOptionPane.showInputDialog ("Enter winning number 4.");
                    sInput=JOptionPane.showInputDialog ("Enter winning number 5.");
                    sInput=JOptionPane.showInputDialog ("Enter winning number 6.");
                    //convert strings to integers
                    iNumber1=Integer.parseInt(sInput);
                    iNumber2=Integer.parseInt(sInput);
                    iNumber3=Integer.parseInt(sInput);
                    iNumber4=Integer.parseInt(sInput);
                    iNumber5=Integer.parseInt(sInput);
                    iNumber6=Integer.parseInt(sInput);
         }//end try
          catch (Exception e)
                    System.out.println ("Invalid input please try again");
                    System.exit (0);
          }//end catch
          for (int i=1; i<=6; i++)
               randNumber = 1 + randomNumbers.nextInt(49);
               array [randNumber] = randNumber;
               if (randNumber==iNumber1)
                         match++;
               else
                         if (randNumber==iNumber2)
                                   match++;
                         else
                                   if (randNumber==iNumber3)
                                             match++;
                                   else
                                             if (randNumber==iNumber4)
                                                       match++;
                                             else
                                                       if (randNumber==iNumber5)
                                                                 match++;
                                                       else
                                                                 if (randNumber==iNumber6)
                                                                           match++;
               if (match==3)
                    prize = 10;
                    if (match==4)
                         prize = 1000;
                         if (match==5)
                              prize = 10000;
                              if (match==6)
                                   prize = 1000000;
          for ( int counter = 1; counter < array.length; counter ++)
                  if (counter % 7 == 0)
                            System.out.printf("%s\n", array [counter]);
                 else
                        System.out.printf("%s ",  array [counter]); 
               if (match >= 3)
                         System.out.println ("You have gotten " + match + "/6 correct\nYou have won $" + prize);
               else
                         System.out.println ("You have gotten " + match + "/6 correct\nSorry you have lost! Please try again");     
}//end class Assignment1

Your problem here as that the exception you want to
throw takes place here
iNumber1=Integer.parseInt(sInput);
public void showMessage(int number){
try{
sInput=JOptionPane.showInputDialog ("Enter
nter winning number " + number);
iNumber1=Integer.parseInt(sInput);
}catch(Exception e){
System.out.println ("Invalid input please try
e try again");
System.exit (0);
}then call this method from inside a for loop:
for(int i=1; i <=6; i++){
showMessage(i);
}Hope that helps you a littleOnly catch NumberFormatException there, though.

Similar Messages

  • Some question about sql code

    for example:
    select
    from testtable
    outputs below results:
    item_desc
    950gapple(z)110ml*40
    650gbanana(z)215ml 1x18
    make above example outputs below result:
    item_desc
    a950gapplez110ml40
    a650gbananaz215ml1x18
    how to write above sql code?
    who can help me?
    thanks

    Jameel Provided solution to one of your other thread
    a question about sql code
    Try the below query. You can modify the TRANSLATE function to add the characters you want to remove from the string.
    select 'a'||replace(translate(str,'()* ','`'),'`') from testtable

  • One last question about Apple IDs

    I thought id asked the lot but there is one last question. How does one delete an Apple ID?
    Many thanks again
    Anthony

    Hello Again Anthony!
    "How does one delete an Apple ID?"
    You can't.
    After you quit using an account, it's posts, will be archived. What that means is, that if there are no additional responses in the Threads they reside in, the Topics will get continually pushed down on the Topics list. After a certain amount of time, maybe 2 to 6 months, the Threads will be locked, so no responses can be entered. But the Threads will not disappear.
    Threads in heavily trafficked Forums, may be archived more rapidly than those in areas, with less activity.
    The Topics that you started using the account, will show your the Alias, in the Author field of a main forum page, but eventually, readers will have to keep going to the succeeding pages to view them.
    If someone were to do a Discussions Search, using these parameters:
    Restrict by Category or Forum: All Categories
    Restrict by Date Range: All
    Restrict by Username: Your Old Alias
    all of your posts, created since about 11/13/05, would be found.
    ali b

  • Ucs question about major code F0283 and dce interfac and chassis number?

    dear,
    Introductions:
    one 6120 connect  chassis 1 one 2104-1 and   chassis 2 one 2104-1
    chassis 1 have sever 3/4/5/6/7/8  (all sever is B200 M3,two 2104)
    chassis 2 have sever 1/2/3/4/5/7 (sever 1/2/3/4 is B200 M3,two 2104)
    question
    1.major code F0283
    all server have  major code F0283 ,but all sever  still can use.what this? How I did it?
    affected object:sys/chassis-1/blade-6/fabric-A/path-1/vc-722
    description: ether vif 1/6 a-722 down,reason: unknown
    chassis 1 have sever 3/4/5/6/7/8
    chassis 2 have sever 1/2/3/4/5/7
    i shutdown all ,and start the problem is also.
    affected 
    i shutdown all ,and start the problem is also.
    2.on chassis 1 sever-1 adapter 1 dce interface (dce interfac 1 and dce interface 5)
    ony one use? 
    3.
    chassis 1 have sever 3/4/5/6/7/8
    chassis 2 have sever 1/2/3/4/5/7
    but i reboot ,
    chassis 2 have sever 3/4/5/6/7/8
    chassis 1 have sever 1/2/3/4/5/7
    so the profile is disorder
    i shtdown all,and start chassis 1 ok ,later chassis 2
    the problem is ok..what this ?

    Hi Hailing,
    The transport VIF for server is down.The Cisco UCS Manager raises this fault when any of the following scenario occur:
    •Endpoint(switch/fabric  interconnect) reports the connectivity state on virtual interface as  one of: a.down, b.errored, c.unavailable.
    Verify  that the blade discovery was completed successfully. Check the states  on all of the communicating ports in an end to end manner.
    If connectivity seems correct, recommision the server.
    Also, please make sure you are using the correct drivers of the OS installed in the server as Padma recommended you.
    I hope this helps.
    David

  • One last question about apple tv!! viewing movies in movies folder

    thanks to those who have responded to my previous questions.
    thinking of buying an apple TV this weekend, but here's my last question (which I just thought of!)
    i've got a collection of movies in various formats, usually .mov or .dv of home videos i've made in FCE and iMovie over the years, some of them several GB in size (oops!)
    what's the best way of viewing these on the apple tv. for instance
    1. does apple TV let you look into your 'movies' folder in the home folder to play any movies it finds there
    2. will it play .dv or .mov files, or does it need to be a specific format
    3. i've noticed an 'export to apple tv' in quicktime pro, do i need to do this for all my movies before apple tv will play them. and after i do an 'export to apple tv' where do the files need to be? imported into itunes, or just sat in my 'movies' folder?
    cheers, looking forward to visiting the apple store tomorrow!

    1. does apple TV let you look into your 'movies' folder in the home folder to play any movies it finds there.
    No, the tv uses itunes for its source of movies.
    2. will it play .dv or .mov files, or does it need to be a specific format
    DV, no. MOV, maybe. MOV is a container type not a compression type, if the MOV container has the correct compression formats in it then it will play. Movies for the tv need to be either mpeg4/2 or mpeg4/10 (H264/AVC)
    3. i've noticed an 'export to apple tv' in quicktime pro, do i need to do this for all my movies before apple tv will play them. and after i do an 'export to apple tv' where do the files need to be? imported into itunes, or just sat in my 'movies' folder?
    Yes 'export to tv' will do the job for you. You need to be aware though that DV with the wrong field dominance will cause it a problem, and some cameras do use the wrong field dominance. It won't work with muxed files (mpeg2 for example) and on SD movies it can be a little wasteful on space. I've always used mpegstreamclip to convert from DV.
    Of course from now on you'll be using FCE with this in mind and exporting accordingly.

  • Vim newbie question about formatting code

    I just started learning vim and am wondering how I can get it to auto format some code.  For example:
    check() {
    for i in $nodes; do
    ping -c 1 $i > /dev/null
    if [ $? -eq 0 ]; then
    echo "Looks like $i is up so initializing the cluster on it."
    ssh $i "\$HOME/bin/cluster-setup.sh"
    fi
    done
    I have tabstop=3 in my ~/.vimrc and I'd just like to apply formatting to that code block so it looks like:
    check() {
    for i in $nodes; do
    ping -c 1 $i > /dev/null
    if [ $? -eq 0 ]; then
    echo "Looks like $i is up so initializing the cluster on it."
    ssh $i "\$HOME/bin/cluster-setup.sh"
    fi
    done
    I read about =i{ but it has no effect for me.
    Thanks!
    Last edited by graysky (2011-06-18 14:32:18)

    graysky,
    If you want vim to autoindent while typing, customize your ~/.vimrc file. I posted mine here: http://linuxandsuch.wordpress.com/2011/06/19/my-vimrc/ a few days back. I recommend all the options.
    However, if you want to indent an already existing file use the indent program. Install with
    sudo pacman -S indent
    And then, to indent your file, run:
    indent myfile.c
    I'd recommend reading the manpage for indent to learn to tweak it to your coding style though .

  • Quick Question About Javascript Code

    I'm trying to write some code in JavaScript so that a different image will display every time someone loads my homepage. I have come across a section called
    'imgct' what does "ct" stand for?
    Please excuse the stupid question but this is my first time!
    If anyone could point me in the right direction of how to do this aswell I would be extremely grateful!
    Thanks
    Kyra

    I'm so sorry about this, it just doesn't seem to be working, I did what you suggested but it still doesn't show up in my browser. :S
    The is the code view of my page now:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link href="Style_sheet.css" rel="stylesheet" type="text/css" />
    <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
    <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
    homeImg = newArray(
    "Images/Homepage/Image1.jpg",
    "Images/Homepage/Image2.jpg",
    "Images/Homepage/Image3.jpg",
    "Images/Homepage/Image4.jpg",
    "Images/Homepage/Image5.jpg"
    ImgCt=homeImg.length;
    function swapImg() {
        if (document.images) {
            randomNum=Math.floor((Mathrandom()*ImgCt));
            document.images ["homePicture"].src = homeImg[randomNum];
    window.onload = swapImg()
    </script>
    </head> 
    <body>
    <div class="container">
      <div class="header">
    *//There is a spry menu bar that goes here//*
        <!-- end .header --></div>
      <div class="content">
      <img src="" name="homePicture" width="627" height="250" id="homePicture" /> </div>
      <noscript><img src="Images/Homepage/Image2.jpg"/></noscript>
    As you can see I have also tried to add in a 'noscript' tag incase someone doesn't have javascript enabled etc. although when I preview it in IE I see both 'Image2' and the image placholder where teh random image is meant to appear, but doesn't.
    I'm very grateful for all the help you are giving me!
    Thank you
    Kyra

  • One last question about capturing from tape

    I have a box full of family VHS tapes that I will be capturing into the computer to digitally archive. However, I want to make sure I am doing it the best possible way. These are the two things most important to me:
    1. Quality
    2. Longevity
    1. Quality
    I have a VHS/MiniDV JVC SR-VS30 deck connected via firewire into my 2014 iMac. I know that firewire is typically the best option when capturing DV footage into the computer. However, is this still true for VHS and other forms of old tape. I can hook anything up to this deck via composite/s-video in and go out through the firewire connection. However, I wasn't sure if firewire was the best coming from a VHS tape. I also have an old video capture card that has a straight s-video/composite input. Which would be more native to the VHS/analog tapes as far as keeping original quality and the best possible image?
    When I use the JVC deck, some programs will capture the vhs tapes and others won't because they won't recognize unless I'm using the DV side. For example, FCPX recognizes the deck, but when I go to import unless it's a dv, it will say "no tape" and I cannot capture anything. iMovie will capture files as .DV. Quicktime will also recognize the deck and capture files as apple prores MOV files. When I compare the QT and iMovie, the QT files look better in my opinion, though I don't know if they truly are. The iMovie dv files have jagged edges like tv lines or something during quick movement and like others say about firewire it looks a little "milky" (though I know this isn't necessarily a bad thing). The QT clips don't necessarily look sharper, but they don't have the hideous jagged edges.
    So my question before I start this large project is:
    Which capture methods above would you use, or what else would you recommend for best quality?
    2. Longevity
    Which file format would you recommend saving these files (or just keeping them as they are at capture) for long term storage? When I come back to these files in 10 years and need to convert them to something new, I want them to have the greatest chance of being compatible with whatever lies ahead. There are so many different file formats.
    Many thanks for any help along this long process

    I want to make sure I am doing it the best possible way.
    I have done lots of that.
    For maximum quality here is my procedure:  ADVC300 > iMovie 06 > iDVD 09/11. 
    To get your VHS video into iMovie, use the Grassvalley ADVC300 .  With the ADVC300 Audio and Video go in, FireWire comes out. It also comes with a nice Macintosh application that works flawlessly with iMovie 06 and iDVD 09/11 (I have used it a few times with iMovie 11).
    The ADVC300 has been discontinued by the manufacturer. The included software (which is not really necessary but does enhance performance) is not compatible with OS 10.7 or newer.  You can still find the ADVC300 for sale in a few outlets as well as eBay. It will sell between 50% and 100% ABOVE its retail price. Yes, it's that good.
    If you can’t find the ADVC300, use the Grassvalley ADVC110.
    I have a drawer full of analog-to-digital converters.   After using the Grass Valley ADVC300 I find nothing else acceptable.
    The program that comes with the ADVC300 has some nice filters that can improve video and audio of the source material. The ADVC300 will take Audio and Video from any source (VCR, Tivo, Satellite Receiver) and convert it to FireWire (iMovie will treat it like a camera).
    I would use iMovie 06 with iDVD 09/11, why?
    iMovie 09, 11, and 13 uses 'single field processing' meaning every other horizontal line of the video is thrown out, which reduces the sharpness of the footage. iMovie 06 uses ALL of the image to form the video.  (Also the latest iMovie CANNOT set Chapeters !)
    After lots of experimenting I get the best results using OS 10.6, iMovie 06, and iDVD 09/11.  My movies look just like Hollywood!
    My primary computer is a Mac Pro, so I just use one of the four hard drives and boot OS 10.6. You can also partition a single hard drive to achieve the same results.
    This may seem like more trouble than you want to go through.  However, I find the superior quality to be well worth it.

  • Question about error code

    I have been having problems when I try to open applications such as IPhotos or Photoshop. They keep on quitting. I did the Hardware Test and it showed error code 2MEM/5/4:DIMM1/J31. Does anyone know what it means and what I should do? I do not have a warranty anymore and now I wondered if I am gonna have to get the coverage plan (my budget is tight right now). Thank you for any help you can give me.

    Either the module has failed or has come loose. At this time I'd open up your computer and make sure it's still locked in place. Afterwards, no need to run the hardware test, just check with System Profiler to see if you were able to nudge it back into position.
    Once in a while RAM modules do fail, but not very often.
    Edit-
    Since you apparently did not purchase this from Apple, it probably is still under lifetime warranty by the seller, so look up your original order number on the invoice and fill out an RMA request on the website of your supplier, or of the manufacturer (brand) itself. If they don't have a Support section or warranty or RMA section, you'll have to email them.
    Put off thinking about eBay until you find out if it will be replaced under warranty.
    [If you had an extra 1GB of memory, that is not going to be a bargain on eBay, as many are just now upgrading and trying to buy that size, but if you had an extra 512MB, then that is what can be found for a fraction of the price you'd have to pay for new anywhere else. If you're really lucky you can find someone with a relatively new iBook or PowerBook who might be looking to sell what hardly had any use. Caution in shipping is required, as the biggest cause of RAM failure is mishandling of the module between manufacture and packaging.]

  • Question about Byte Code

    Hello...can anyone tell me how I write a java program, compile it and get my byte code written into another file??
    Thanks in advance!

    I am looking to write my bytecode into a .bc file and
    open it and actually be able to read the bytecode
    instruction...(stuff like iload_2, i2d etc.,)I see... that was not clear from your first question. What you want is a disassembler. The SDK comes with one called 'javap': http://java.sun.com/j2se/1.4.1/docs/tooldocs/windows/javap.html

  • Question about error-code in web.xml

    Can you use pattern matching for error-codes?
    Instead of
    <error-code>401</error-code>
    <error-code>403</error-code>
    <error-code>404</error-code>
    etc..
    you could just do
    <error-code>4*</error-code>

    I don't know a replacement for this, but I recommend to post this questione into Servlets section to get more chances for receiving answers...
    Regards,
    Mohammed Saleem

  • Questions about byte code

    1.How can a java program mutate and kill itself after running a certain times?
    i think the argorithm is to modify the byte code, but i don't know the structure of the byte code.
    for example:
    "int i=1156;
    victim.seek(i);
    int changed_byte=(int)victim.readUnsignedByte()+1;
    victim.seek(i);
    victim.writeByte(changed_byte);"
    how can i know that 1156 is the place that count the running times of the program. please help me and give the relevent pages to read, many thanks!

    In Mustang, the java.lang.instrument API has been extended to allow not only redefinition of classes, but also retransformation (without / with original bytes, respectively), so you could hook up a Java agent to transform classes at will. You could use this with 5.0, but you can't get the actual bytes for the current class from the JVM when retransforming classes. See http://java.sun.com/j2se/1.5.0/docs/api/java/lang/instrument/package-summary.html#package_description and http://download.java.net/jdk6/docs/api/java/lang/instrument/package-summary.html#package_description for more on instrumentation in 5.0 and (provisionally) 6.0.
    You might find a tool I've been working on lately useful: http://jen.dev.java.net/ - It basically presents a mutable class with a collections-ish interface and allows you to generate as bytes or a Class. It can be used in regular code, in agents, with .class files, byte arrays, java.lang.Classes, and so on.
    However, I would question your motivation here, particularly since you're using names like 'victim' and 'attacker'. You will struggle to do any of this is the user really doesn't want you to, since the platform is designed pretty well against it.

  • Question about JS code hinting

    When dreamweaver codehints javascript the code options have a little icon to the left
    i have seen red squares, hollow green circles, and yellow squares balanced on on it's its corners.
    what do these symbols mean?

    Company code is create  for legal requirement purpose.
    ex:  You have create A Comapany. company act 1956 every comapny has submmited the financial years Balance sheet and profit loss a/c govtment.
    Business area:  to veiw the divisional wise balance sheet and profit loss a/cit is mainpurpose of business area.

  • Question about Alerttypes (code included)

    Hi,
    I have this code where I'm comparing two dates, if its outdated then the program will exit. That works perfectly. But when the program is outdated a screen is supposed to be shown to the user and prompt a text. I can only get this screen to show very very quick, what I'd really want is for this screen to be shown and have the user press like "OK" or any key for that matter to exit the program, just to make sure they actually get a chance to read it. I thought my code (shown below) would do that, but apparently it doesnt .. so .. please help me with an advice on how to fix it =)
         if (todayNum > endDate) {
              Alert alert = new Alert("Demo version outdated", "This demoversion is outdated. Please request a new version.", null, AlertType.CONFIRMATION);
              Display.getDisplay(this).setCurrent(alert);
         // Program done, exit now
              destroyApp(true);
              notifyDestroyed();
         }

    I meant a custom CommandListener, not alert, i hope that doesnt confuse things
    quick example, without checking the API (but to give an idea of what i mean) would be something like:
    Alert endAlert = new Alert("Demo version outdated", "This demoversion is outdated. Please request a new version.", null, AlertType.CONFIRMATION);
    endAlert.addCommand(new Command("ok", Command.OK, 1));
    endAlert.setCommandListner(new CommandListener() {
    public void commandAction(Command c, Displayable d) {
    destroyApp(true);
    notifyDestroyed();
    Display.getDisplay(this).setCurrent(alert);

  • Question about changing code progammatically

    In our code base there are many pkgs, procedures, and functions that have an email in the exception block. This email needs to be removed/updated.
    Can these objects be updated in a loop? Would you use execute immediate to re-compile? Would a cursor be used to determine from all_source which objects needed to be updated?
    Has anyone done this before or do we need to re-compile each, one at a time?

    Something like that could work:
    begin
       for c in
          (select object_name,
                  replace (dbms_metadata.get_ddl (object_type, object_name),
                           '[email protected]',
                           '[email protected]'
                          ) stmt
             from user_objects
            where object_type in ('PROCEDURE', 'PACKAGE', 'FUNCTION', 'TRIGGER')
              and dbms_metadata.get_ddl (object_type, object_name) like
                                                             '%[email protected]%')
       loop
          execute immediate cast (c.stmt as long);
       end loop;
    end;

Maybe you are looking for

  • Issue Invoking 10.1.2 BPEL Process from 10.1.3 Embedded server.

    Hi All, I am trying to connect to BPEL 10.1.2 from 10.1.3 embedded server. When I run following code in debug it just stays at Locator locator = new Locator("default","bpel",jndi); line. It does not give any error message. Please help. Let me know if

  • Only German Language fails in Portal view of SUS app

    Hello, We are running SAP's SUS (Supplier Self Services) through the portal.  Everything works fine in any language except German.  German works when using SUS through the backend.  When a user with the German Language set opens the Self Services tab

  • Apple Hardware Test Unavailable? Mac Pro 2008, Mavericks installed

    Restarting my early 2008 Mac Pro with Mavericks installed while holding down the "D" key and it's just booting up like normal. Tried holding it before it shuts down, holding it after the startup tone, and holding it after the grey screen appears (whi

  • Desktop Manager shuts down without prompt in the middle of sync

    Hello All, My desktop manager shuts down without prompt in the middle of sync without an error message.  Each time I sync I have to reopen it mutiple times before a sync in completed.  Has anyone else experieced this BB 8830 Windows XP OS

  • Ruby gems installed from AUR leave files behind if removed again

    Most Ruby gems in the AUR use the PKGBUILD snippet provided by http://wiki.archlinux.org/index.php/Rub - Guidelines – now I think that using "gem install" will avoid the sandbox and also make it impossible for yaourt/clyde/- to keep track of the inst