Results 1 to 4 of 4
  1. #1
    noahwhygodwhy is offline Member
    Join Date
    Mar 2011
    Posts
    10
    Rep Power
    0

    Question BPA registration simulation again, Almost done

    When ever i tried to enter no, it said that it was a number format exception on line 178, which is if(Integer.parseInt(SPChoice) < 18). It is saying that n is not a number, which is correct, but I have a if statement; if(SPChoice != "n") preventing it from processing a n. But it still tries to process it. Any ideas?:confused: Here is the problem code:


    if(SPChoice != "n")
    {
    if(Integer.parseInt(SPChoice) < 18)
    {
    System.out.println("Would you like to go to Sixflags Fiesta? 'y' or 'n'");
    String fiestaC = kb.next();
    if(fiestaC.equals("y"))
    {

    fiesta = 25;
    }
    System.out.println("You can also go to the luncheoneon, would you like to? 'y' or 'n'");
    String luncheonC = kb.next();
    if(luncheonC.equals("y"))
    {
    luncheon = 10;
    }
    }
    if(Integer.parseInt(SPChoice) >17)
    {
    System.out.println("Would you like to go to Sixflags Fiesta? 'y' or 'n'");
    String fiestaC = kb.next();
    if(fiestaC.equals("y"))
    {
    fiesta = 25;
    }
    }
    }
    When i previewed it i noticed it messed up the brackets, they are ok, it's just when i copied it to the post did it mess up.

  2. #2
    noahwhygodwhy is offline Member
    Join Date
    Mar 2011
    Posts
    10
    Rep Power
    0

    Default

    I meant to say, when i tried to enter n. sorry

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Do not compare objects with logical operators. Use the equals method instead.
    Java Code:
    x.equals(y)
    ! x.equals(y)

  4. #4
    noahwhygodwhy is offline Member
    Join Date
    Mar 2011
    Posts
    10
    Rep Power
    0

Similar Threads

  1. BPA registration simulation
    By noahwhygodwhy in forum New To Java
    Replies: 4
    Last Post: 04-04-2011, 12:47 AM
  2. JSP Registration Form error
    By ak88 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 10-26-2009, 10:54 AM
  3. help in registration
    By katrinax_caren02 in forum JDBC
    Replies: 1
    Last Post: 09-27-2009, 03:46 PM
  4. Registration Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-25-2007, 11:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •