Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class username {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. {
  8. int UseLift;
  9. int AuditReport;
  10. int ExitLift;
  11. int a;
  12.  
  13. UseLift = 1;
  14. AuditReport = 2;
  15. ExitLift = 3;
  16. }
  17.  
  18. System.out.println("choose an option");
  19. System.out.println("Uselift(1)");
  20. System.out.println("see audit report(2)");
  21. System.out.println("Exit Lift(3)");
  22.  
  23. Scanner d = new Scanner(System.in);
  24. int a = d.nextInt();
  25.  
  26. Scanner kb = new Scanner(System.in);
  27. // array containing usernames
  28. String[] name = {"barry", "matty", "olly", "joey"}; // elements in array
  29.  
  30. if (a == 1) {
  31. System.out.println(" Enter your name ");
  32. }
  33.  
  34. String name1 = kb.nextLine();
  35. boolean b = true;
  36. int j = 0;// counter will start at 0
  37. outerloop:
  38.  
  39. while (j < 3) {
  40. System.out.println("Enter your name");
  41. }
  42.  
  43. for (int i = 0; i < name.length; i++) {
  44. if (name[i].equals(name1)) {
  45. System.out.println("you are verified you may use the lift, calling lift ");
  46. }
  47. break;// to stop loop checking names
  48. }
  49. System.out.println("Username Invalid");
  50. j++;
  51.  
  52. if (a == 2) {
  53. System.out.println("");
  54. }
  55.  
  56. if (a == 3) {
  57. System.out.println(" Please Exit Lift ");
  58. }
  59. }
  60. }
  61.  
  62. public static void main(String... args) {
  63.  
  64. String[] verifiedNames = { "barry", "matty", "olly", "joey" };
  65. System.out.println("choose an option");
  66. System.out.println("Uselift(1)");
  67. System.out.println("see audit report(2)");
  68. System.out.println("Exit Lift(3)");
  69.  
  70. Scanner scanner = new Scanner(System.in);
  71. int choice = scanner.nextInt();
  72.  
  73. switch (choice) {
  74. case 1:
  75. scanner.nextLine(); // get 'n' symbol from previous input
  76. int nameAttemptsLeft = 3;
  77. while (nameAttemptsLeft-- > 0) {
  78. System.out.println(" Enter your name ");
  79. String name = scanner.nextLine();
  80.  
  81. if (Arrays.asList(verifiedNames).contains(name)) {
  82. System.out.println("dear " + name + " you are verified " +
  83. "you may use the lift, calling lift ");
  84. break; // break out of loop
  85. }
  86. }
  87. if (nameAttemptsLeft < 0) {
  88. System.out.println("Username Invalid");
  89. }
  90. break;
  91.  
  92. case 2:
  93. System.out.println("option 2");
  94. break;
  95. case 3:
  96. System.out.println(" Please Exit Lift ");
  97. break;
  98. }
  99.  
  100. scanner.close();
  101.  
  102. }
  103.  
  104. while (j < 3) {
  105. System.out.println("Enter your name");
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement