Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import javax.swing.JOptionPane; //Import JOptionPane Class
  2.  
  3. public class P1I
  4. {
  5. public static void main (String args[])
  6. {
  7. //Stored info
  8. String my_username = "Joanne";
  9. int my_password = 1234;
  10.  
  11. String username = JOptionPane.showInputDialog ("Enter username:"); //Dialog to get username
  12. String password = JOptionPane.showInputDialog ("Enter password"); //Dialog to get password
  13.  
  14. int int_password = Integer.parseInt(password); //Convert String "password" into integer "int_password". This is done so that the stored password integer and the string can be compared directly. Also, this allows for calculations to be performed on the value.
  15.  
  16. if (username.equals(my_username) && (int_password == my_password)) //Check if entered username and password matches the stored ones
  17. {
  18. System.out.println("Login Successful!");
  19. }
  20. else //If info do not match
  21. {
  22. System.out.println("Login Unsuccessful!");
  23. }
  24. System.exit(0); //End the program
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement