Results 1 to 6 of 6
  1. #1
    murr0508 is offline Member
    Join Date
    Feb 2009
    Posts
    4
    Rep Power
    0

    Default Error message pops up no matter what?

    public void deliveryCharge()
    {

    // VARIABLE DECLARATIONS/DEFINITIONS (IPO) ********************************************

    // *** INPUT VARIABLES ***
    DecimalFormat dollarDecimalPlaces = new DecimalFormat("$#,##0.00");//This is the dollar decimal format that gives the dollar amounts a dollar sign the correct decimal format.
    String userName; //The user's name
    String pickupOption; //Find out if the user is picking up
    String packageWeightInfo;//String regarding to weight of package in pounds
    double packageWeight = 0;//Weight of the package in pounds
    double pickupCharge = 0;//Charge if user picks up package
    char Y;
    char X;
    // *** PROCESSING VARIABLES ***
    // (These may be constants intermediate or temporary storage variables.)
    double cost = 0; //Cost per pound
    // *** OUTPUT VARIABLES ***
    double deliveryCharge;//This is the result of the program
    // THE CODING STATEMENTS/ACTIONS (IIPO) ***********************************************

    // INITIALIZATION
    JOptionPane.showMessageDialog(null, "Welcome to the Dawg Delivery Service!");//Displays a welcoming message to the user

    // INPUTS - COLLECT INPUT FROM THE USER OR ANOTHER SOURCE - AND VALIDATE THE INPUTS.
    //Get the User's name:

    userName = JOptionPane.showInputDialog("Please enter your full name.");//Asks the user to enter their name
    if (userName.length() == 0)
    {
    JOptionPane.showMessageDialog(null, "ERROR! You cannot have a length of zero!"); //If nothing is entered in the userName input box, then this will pop up.
    System.exit(0);
    }
    pickupOption = JOptionPane.showInputDialog("Is this package being picked up? Please enter Y or N:");//Asks user to enter if the package is being picked up. Only Y or N will be acceptable for answers.
    if (pickupOption.substring(0,1).equals("Y") || pickupOption.substring(0,1).equals("y"))

    {

    pickupCharge = 2; //Gives correct pick up charge if item is picked up
    }

    if (pickupOption.substring(0,1).equals("N") || pickupOption.substring(0,1).equals("n"))
    {

    pickupCharge = 0; //Gives zero pick up charge if item is not picked up
    }
    if (pickupOption.substring(0,1) != ("N") || pickupOption.substring(0,1) != ("n"))
    {
    JOptionPane.showMessageDialog(null, "ERROR! You must enter Y or N!"); //If something other than Y or N is entered, then this will pop up.
    System.exit(0);
    }
    if (pickupOption.substring(0,1) != ("Y") || pickupOption.substring(0,1) != ("y"))
    {
    JOptionPane.showMessageDialog(null, "ERROR! You must enter Y or N!"); //If something other than Y or N is entered, then this will pop up.
    System.exit(0);
    }



    When my program is running, no matter what I type in for the pickupOption, it gives me my error message. WHY???

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    It's very hard to read your code as it has not retained its formatting.

    Please use code tags so that your code will be well-formatted and readable. To do this, either highlight your code block and press the "code" button at the top above the message block or place the tag [code] at the top of your block of code and the tag [/code] at the bottom, like so:

    Java Code:
    [code]
       // your code block goes here
       // notice that the top and bottom tags are different here
    [/code]
    Good luck

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Also, what is the error message? And what line of code causes it?

    also, don't use == or != for String. Use either the equals method or equalsIgnoreCase method.
    Last edited by Fubarable; 02-26-2009 at 10:34 PM.

  4. #4
    murr0508 is offline Member
    Join Date
    Feb 2009
    Posts
    4
    Rep Power
    0

    Default

    I'm not really sure how to use this site completely yet. The message I get is the JOptionPane I created that says "ERROR! You must enter Y or N!"
    I have to somehow get that to only pop up when the user enters something other than Y, y, N, or n. I do not know how to go about doing that so that's why I did the

    if (pickupOption.substring(0,1) != ("N") || pickupOption.substring(0,1) != ("n"))
    {
    JOptionPane.showMessageDialog(null, "ERROR! You must enter Y or N!"); //If something other than Y or N is entered, then this will pop up.
    System.exit(0);
    }

    Is there a better or more correct way to make this only pop up when something other than those chars are entered? Thanks!

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Again:
    1) use code tags when posting code. Shoot, I showed you how to do this, so it shouldn't be hard.
    2) Again, don't use == or != when comparing Strings.
    3) Figuring out how to get your logic to work will take some sitting and thinking without your computer. Work on paper to figure out the correct logic -- it's not hard with just a little effort. One way is to check for all the correct letters using a single if statement, another is to use a few if then else if statements,... but again, it's far better if you are the one who figures this out. You can do it.

  6. #6
    murr0508 is offline Member
    Join Date
    Feb 2009
    Posts
    4
    Rep Power
    0

    Default

    I just realized my mistake. All it needed was one else if statement for the n chars as well as the last statement to be a plain "else" statement for anything else entered. Thank you for your help.

Similar Threads

  1. Error Message in JBuilder
    By RavenNevarmore in forum New To Java
    Replies: 4
    Last Post: 10-08-2008, 07:53 AM
  2. strange Error message
    By little_polarbear in forum New To Java
    Replies: 4
    Last Post: 08-26-2008, 12:45 AM
  3. Can't solve error message while looping
    By BHCluster in forum New To Java
    Replies: 15
    Last Post: 04-22-2008, 11:51 AM
  4. java error message
    By baileyr in forum New To Java
    Replies: 2
    Last Post: 01-23-2008, 04:47 AM
  5. error message on jsp
    By sandor in forum Web Frameworks
    Replies: 1
    Last Post: 04-11-2007, 03:10 AM

Posting Permissions

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