Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

java questio: how do you say not equals to in this line of code:

  • 07-03-2006 1:14pm
    #1
    Registered Users, Registered Users 2 Posts: 1,073 ✭✭✭


    if(strPassword.equals(password) && strUsername.equals(username))

    // i wanna say if (strPassword is not equal to password && strUsername is not equal to username)

    //any ideas lads
    //thanks so much
    // xxx
    // :);)


Comments

  • Closed Accounts Posts: 2,653 ✭✭✭steviec


    if(!strPassword.equals(password) && !strUsername.equals(username))


    ! is the symbol for not.

    Also from a program logic point of view I imagine you want OR instead of AND, which would be || instead of &&


  • Registered Users, Registered Users 2 Posts: 1,275 ✭✭✭bpmurray


    Actually, you want to say if strPassword is not equal to password OR strUsername is not equal to username ....
    if (!strPassword.equals(password) || !strUsername.equals(username))
    

    or, alternatively, simply negate your original suggestion:
    if (!(strPassword.equals(password) && strUsername.equals(username)))
    


  • Registered Users, Registered Users 2 Posts: 1,073 ✭✭✭eurotrotter


    thanks for the help lads
    iv siunce written the login to only allow 4 attempts
    but it makes the dialog boxes pop up 2 times each time a password is wrong
    iv worked so hard at this!
    could ye splease tell me where i might be going wrong
    thanks lads
    hre it is:
    if(strPassword.equals(password) && strUsername.equals(username))
    {
    JOptionPane.showMessageDialog(null, "Welcome to the Administrator's menu");
    passwordTxt.setText("");
    this.setVisible(false);
    admin example= new admin();
    example.setVisible(true);

    }




    if (!strPassword.equals(password) || !strUsername.equals(username))
    {
    int i = 0;

    for(i=0;i<4;i++)
    {
    passwordTxt.setText("");
    JOptionPane.showMessageDialog(null, "Password Incorrect,Please try again");
    i++;
    }
    for(i=4;i<5;i++)
    {
    passwordTxt.setText("");
    JOptionPane.showMessageDialog(null, "get out");

    }

    }


  • Registered Users, Registered Users 2 Posts: 1,275 ✭✭✭bpmurray


    If you go into the first if (), you set the password to "". So the second if() also succeeds. What you need is:
     if(strPassword.equals(password) && strUsername.equals(username)) {
    blah blah
    } else {
    <test for the wrong password here>
    }
    

    In fact, I wouldn't even do that. Instead use a while loop ...
    int count = 4;
    
    while (count > 0 &&  !(strPassword.equals(password) && strUsername.equals(username))) {
       JOptionPane.showMessageDialog(null, "Password Incorrect,Please try again");
       count--;
    }
    if (count > 0) { // Only happens if the answer is right!
       JOptionPane.showMessageDialog(null, "Welcome to the Administrator's menu");
       passwordTxt.setText("");
       this.setVisible(false);
       admin example= new admin();
       example.setVisible(true);
    }
    


  • Registered Users, Registered Users 2 Posts: 1,073 ✭✭✭eurotrotter


    o thanks a million
    hopw this works!
    thanks :)
    im at work at the mometn cant wait to test it!
    bpmurray wrote:
    If you go into the first if (), you set the password to "". So the second if() also succeeds. What you need is:
     if(strPassword.equals(password) && strUsername.equals(username)) {
    blah blah
    } else {
    <test for the wrong password here>
    }
    

    In fact, I wouldn't even do that. Instead use a while loop ...
    int count = 4;
    
    while (count > 0 &&  !(strPassword.equals(password) && strUsername.equals(username))) {
       JOptionPane.showMessageDialog(null, "Password Incorrect,Please try again");
       count--;
    }
    if (count > 0) { // Only happens if the answer is right!
       JOptionPane.showMessageDialog(null, "Welcome to the Administrator's menu");
       passwordTxt.setText("");
       this.setVisible(false);
       admin example= new admin();
       example.setVisible(true);
    }
    


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,073 ✭✭✭eurotrotter


    thanks for the code bp,
    but it didnt work properly, when an incorrect password is entered a dialogbox comes up and says that its incorrect however it comes up three times and then it cmoes up 4 times
    thanks so much for your help to that
    xxx


    bpmurray wrote:
    If you go into the first if (), you set the password to "". So the second if() also succeeds. What you need is:
     if(strPassword.equals(password) && strUsername.equals(username)) {
    blah blah
    } else {
    <test for the wrong password here>
    }
    

    In fact, I wouldn't even do that. Instead use a while loop ...
    int count = 4;
    
    while (count > 0 &&  !(strPassword.equals(password) && strUsername.equals(username))) {
       JOptionPane.showMessageDialog(null, "Password Incorrect,Please try again");
       count--;
    }
    if (count > 0) { // Only happens if the answer is right!
       JOptionPane.showMessageDialog(null, "Welcome to the Administrator's menu");
       passwordTxt.setText("");
       this.setVisible(false);
       admin example= new admin();
       example.setVisible(true);
    }
    


  • Registered Users, Registered Users 2 Posts: 1,275 ✭✭✭bpmurray


    That's odd. What should happen is that if you give the wrong password, it'll say "Password Incorrect". This is allowed up to four times, and then it'll fall through. If, however, you give the correct password, it'll drop inot the next "Welcome to the Admin..." part.

    I think you may have included this method in the wrong place.


  • Registered Users, Registered Users 2 Posts: 1,073 ✭✭✭eurotrotter


    iv attached the login code there
    i was looking at your code as weoll last night it hould work
    its perfect
    anyway its prob summit im doing wrong as usual!
    thanks for the help bp
    ;)


  • Registered Users, Registered Users 2 Posts: 1,275 ✭✭✭bpmurray


    iv attached the login code there
    anyway its prob summit im doing wrong as usual!
    No - my fault: the loop was trying to independently check for the error without waiting for more input. Here's the updated code: I reformatted it to make it more legible, but it's your code anyway.

    BTW, it's more usual for the first character of your class to be in uppercase.


  • Registered Users, Registered Users 2 Posts: 1,073 ✭✭✭eurotrotter


    thanks a million
    unreal sound oof ya
    really now thanks
    if theres anything i can do for ya
    il check th eocde late on iat work with no compiler
    thanks!


    bpmurray wrote:
    No - my fault: the loop was trying to independently check for the error without waiting for more input. Here's the updated code: I reformatted it to make it more legible, but it's your code anyway.

    BTW, it's more usual for the first character of your class to be in uppercase.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,073 ✭✭✭eurotrotter


    it worked perfectly bp thanks again bud!
    i have one more questio though: here it is:

    I want the mmovie names and movie times to appear as soon as the program is run but iv only managed to get the movienames and movie times to appear on a button click
    i have attached the two files
    if you could have a look id be so greatful as I'm so close to getting a 100% properly functioning cinema program!
    thank again


  • Registered Users, Registered Users 2 Posts: 1,275 ✭✭✭bpmurray


    Well, you should use Eclipse which has got a bunch of refactoring and formatting functions. You should avoid global variables if at all possible. And again, the class should start with an uppercase character.

    You seem unenthusiastic about creating methods that can be reused - on load you need to run the data load functionality, so that should be pulled out. See the changes I made.


  • Registered Users, Registered Users 2 Posts: 1,073 ✭✭✭eurotrotter


    bpmurray wrote:
    Well, you should use Eclipse which has got a bunch of refactoring and formatting functions. You should avoid global variables if at all possible. And again, the class should start with an uppercase character.

    You seem unenthusiastic about creating methods that can be reused - on load you need to run the data load functionality, so that should be pulled out. See the changes I made.
    thanks for that but to be hgonest id prefer to leave my code as intact as I can regardless of its messy format
    could you lplease just change it as little as possible
    i know now that might sound cheaky to you but i need it to relate to the notes we got in class too you see
    thanks so so much
    means so mcuh
    thanks :);)


  • Closed Accounts Posts: 14 modal_ie


    if(strPassword.equals(password) && strUsername.equals(username))
    {
    JOptionPane.showMessageDialog(null, "Welcome to the Administrator's menu");
    passwordTxt.setText("");
    this.setVisible(false);
    admin example= new admin();
    example.setVisible(true);

    }
    else
    {
    int i;

    for(i=0;i<4;i++)
    {
    passwordTxt.setText("");
    JOptionPane.showMessageDialog(null, "Password Incorrect,Please try again");
    i++; /*Are you sure you mean to do this???*/
    }
    for(i=4;i<5;i++)
    {
    passwordTxt.setText("");
    JOptionPane.showMessageDialog(null, "get out");

    }
    }


Advertisement