Results 1 to 8 of 8
  1. #1
    Frög is offline Member
    Join Date
    Feb 2009
    Posts
    5
    Rep Power
    0

    Default InputDialog & MessageDialog HELP?!

    Hello, as you can see, I am new.. I am Student programmer and need help from you wise seniors!

    I have to have a InputDialog asking if the package is being picked up. If so, I have to add a 2$ fee.

    My program asks me if it is being picked up and w/e I type in the box, NOTHING HAPPENS! No message error like I thought I had and the machine has to be reseted..

    Any help would be greatly appreciated!

    //Variables

    double pickUp;
    boolean yesPickUp = false;
    boolean noPickUp = false;


    //Process Variables:
    String inputString;

    inputString = JOptionPane.showInputDialog("Are you picking up the Package?" +
    " Please enter \"Yes\" or \"No\"");
    inputString = readString();
    if ((inputString == "yes")||(inputString == "Yes"))
    {
    yesPickUp = true;
    pickUp = 2.00;
    }
    else if ((inputString == "no")||(inputString == "no"))
    {
    noPickUp = true;
    pickUp = 0.;
    }
    else
    {
    JOptionPane.showMessageDialog(null, "***Error - Invalid entry! Exiting!***");
    return; // quit the method.
    }

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Welcome...

    Well welcome to the Java Forums...
    You didn't post all of the program, but I do see one glaring error, very common ot new beginners..
    Java Code:
    if ((inputString [B][COLOR="Red"]==[/COLOR][/B] "yes")||(inputString [COLOR="red"][B]==[/B][/COLOR] "Yes"))
    You can't compare strings using "==" ... you have to use the string method equals().. an example:
    Java Code:
    if(barney[B][COLOR="Blue"].equals[/COLOR][/B]("Fred"))
    Luck, CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default tip...

    I'll also throw in a tip....
    To avoid having to check if the user's input is "yes" or "Yes" or "YES" or....
    just make the user's input all lower case:
    Java Code:
    if (inputString[B][COLOR="Blue"].toLowerCase()[/COLOR][/B].equals("yes"))
    That way, no matter how the user input's the word, it will always compare evenly.
    Here's the link to Java API for the String class and all it's methods:
    String (Java Platform SE 6)
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

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

    Default

    You have if inputString == 'yes' || and your else if are both "no"

    try if inputString.equalsIgnoreCase("Yes")

    Also as you are only wanting a 'Yes' 'No' reponse, try using a
    JOptionPane.showConfirmDialog(new JFrame(), "Data you want or question in here, JOptionPane.YES_NO_OPTION)

    This then sets a new framed window with a yes no button then your IF /Else if statemsnts will look like this.

    if (inputString== JOptionPane.NO_OPTION)
    else if (inputString== JOptionPane.YES_OPTION)

  5. #5
    Frög is offline Member
    Join Date
    Feb 2009
    Posts
    5
    Rep Power
    0

    Default How do I do this?

    Thank you for the fast response. WOW I am so glad I joined this forum!!


    After the question about pickup, Weight of the package is asked.

    Following these rules:

    Parcel Weight (pounds) Cost per pound ($)
    ------------------------- -----------------
    Less than 2.5 pounds $3.50 / pound
    2.5 pounds to 5.0 pounds $2.85 / pound
    greater than 5 pounds $2.45 / pound
    ------------------------- -----------------

    So I have a "weightFactor" where my calculation looks like

    deliveryCharge = weightFactor * weight

    But all this is nice and dandy but if the Item is picked up, I must ignore these.. How to I force this?

    I was thinking of doing this:

    deliveryCharge = weightFactor * weight + pickUp

    where the pickUp is 2.00 if "YES" or 0.00 if "NO".. Works for the "NO" but not the "Yes".. Is this where I have to use a boolean? And how?

  6. #6
    JohnnyR is offline Member
    Join Date
    Feb 2009
    Posts
    46
    Rep Power
    0

    Default

    It's a little hard with out looking at your code.
    Can you post it? you should be able to have the returned information and base your decision on that and then have a 'else' factor for the ignoring it.

    Did the first part we replied to help you ? Which part was the actual root cause?

  7. #7
    Frög is offline Member
    Join Date
    Feb 2009
    Posts
    5
    Rep Power
    0

    Default

    Ill post the program, I just didn't want other students to copy my work. Once I post it, it will explain everything..

    brb

  8. #8
    Frög is offline Member
    Join Date
    Feb 2009
    Posts
    5
    Rep Power
    0

    Default

    Actually, I think it is working the way I want it to.. mhmmmm weird..

    I don't know if I am done just yet, but so far, THANKS to all of you!!!

Similar Threads

  1. [SOLVED] N2J - inputDialog
    By obdi in forum New To Java
    Replies: 3
    Last Post: 07-15-2008, 09:07 AM
  2. JFace's InputDialog Demonstration
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 05:40 PM
  3. JFace's MessageDialog Demonstration
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 05:39 PM
  4. Demonstration of the custom InputDialog class
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-02-2008, 08:56 PM

Posting Permissions

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