/*** Password ID Check ********************
This program inputs a user name and password
and checks whether these match each other.
It uses pop-up INPUT and OUTPUT windows.
*******************************************/
This program shows how to use if...else
if ... else if ... else.. to choose exactly one action from a
list of many choices.
Each else if... is only tested
when the previous if.. is not
true. Whenever one of the checks succeeds, the rest of the
choices are not tested.
if( name.equals("Admin") && pw.equals("master") )The if.. command checks whether the user name is correct (Admin) AND the password is correct (master).
{ output("Hello master"); }
else if ( name.equals("RONALD") && pw.equals("clown") ) { output("Ha..ha..hallo"); }If these are correct, it prints "Ha..ha..hallo". Otherwise, it goes on to check the next combination:
else if ( name.equals("secret") && pw.equals("magic") ) { output("Okay"); }If this still doesn't work, then it goes on to the default result:
else { output("Rejected! Who are you?"); }So if none of the combinations match the input, it prints "Rejected..." for any other input.
if( name.equalsIgnoreCase("Admin") && pw.equalsIgnoreCase("master") )This would accept "admin" and "master" typed with any combination of capital and small letters:
{ output("Hello master"); }
Ronald , clown , 999Then you need 3 input commands, as well as checking THREE things in