Advertisement
Guest User

Untitled

a guest
Apr 15th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. public class User
  2. {
  3. private String userID;
  4. private String password;
  5. private Employee employee;
  6. private String authorityLevel;
  7. /**
  8. * Constructor for User class - Initialise a fixed password and employee object.
  9. */
  10. public User()
  11. {
  12. employee = new Employee();
  13. password = "password";
  14. }
  15.  
  16. /**
  17. * Create a user ID and print the user the details of their user account.
  18. */
  19. public void createUser(Employee employee)
  20. {
  21. // Combine staff ID with authority key to make the user ID.
  22. userID = employee.getID() + "" + employee.getAuthorityLevel();
  23.  
  24. // Check that there is a staff ID to create the user ID.
  25. // It also ensures that an employee profile has been created before an attempt
  26. // to make a user account.
  27. if(employee.getID() == null){
  28. System.out.println("There are no Employee details to make a User with.");
  29. System.out.println("Please enter the Employee details before you make a user");
  30. }
  31. else{
  32. System.out.println("Your user ID is: "+userID);
  33. System.out.println("Your user password is: "+password);
  34. }
  35. }
  36.  
  37. /**
  38. * @return The user ID.
  39. */
  40. public String getUserID()
  41. {
  42. return userID;
  43. }
  44.  
  45. /**
  46. * @return The password.
  47. */
  48. public String getPassword()
  49. {
  50. return password;
  51. }
  52. }
  53.  
  54. public class Login
  55. {
  56. private User user;
  57. private boolean accessGranted;
  58. private String userID;
  59. private String password;
  60. private boolean loggedIn;
  61. private boolean loggedOut;
  62. /**
  63. * Constructor for the Login class - initialise a user object.
  64. */
  65. public Login()
  66. {
  67. user = new User();
  68. }
  69.  
  70. /**
  71. * Attempt to start a login session.
  72. */
  73. public void login(String userID,String password)
  74. {
  75. // Check that credentials entered are correct for the account the user wishes to log in to.
  76. if((password == user.getPassword()) && (userID == user.getUserID())){
  77. accessGranted = true;
  78. if((accessGranted == true) && (userID.contains("H"))){
  79. System.out.println("Your login session has started.");
  80. System.out.println("You are now viewing Yuconz System as HR staff.");
  81. }
  82. if((accessGranted == true) && (userID.contains("D"))){
  83. System.out.println("Your login session has started.");
  84. System.out.println("You are now viewing Yuconz System as Director staff.");
  85. }
  86. if((accessGranted == true) && (userID.contains("E"))){
  87. System.out.println("Your login session has started.");
  88. System.out.println("You are now viewing Yuconz System as Employee staff.");
  89. }
  90. loggedIn = true;
  91. }
  92. else{
  93. System.out.println("ACCESS DENIED BRUTHA!");
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement