Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class username {
- public static void main(String[] args) {
- {
- int UseLift;
- int AuditReport;
- int ExitLift;
- int a;
- UseLift = 1;
- AuditReport = 2;
- ExitLift = 3;
- }
- System.out.println("choose an option");
- System.out.println("Uselift(1)");
- System.out.println("see audit report(2)");
- System.out.println("Exit Lift(3)");
- Scanner d = new Scanner(System.in);
- int a = d.nextInt();
- Scanner kb = new Scanner(System.in);
- // array containing usernames
- String[] name = {"barry", "matty", "olly", "joey"}; // elements in array
- if (a == 1) {
- System.out.println(" Enter your name ");
- }
- String name1 = kb.nextLine();
- boolean b = true;
- int j = 0;// counter will start at 0
- outerloop:
- while (j < 3) {
- System.out.println("Enter your name");
- }
- for (int i = 0; i < name.length; i++) {
- if (name[i].equals(name1)) {
- System.out.println("you are verified you may use the lift, calling lift ");
- }
- break;// to stop loop checking names
- }
- System.out.println("Username Invalid");
- j++;
- if (a == 2) {
- System.out.println("");
- }
- if (a == 3) {
- System.out.println(" Please Exit Lift ");
- }
- }
- }
- public static void main(String... args) {
- String[] verifiedNames = { "barry", "matty", "olly", "joey" };
- System.out.println("choose an option");
- System.out.println("Uselift(1)");
- System.out.println("see audit report(2)");
- System.out.println("Exit Lift(3)");
- Scanner scanner = new Scanner(System.in);
- int choice = scanner.nextInt();
- switch (choice) {
- case 1:
- scanner.nextLine(); // get 'n' symbol from previous input
- int nameAttemptsLeft = 3;
- while (nameAttemptsLeft-- > 0) {
- System.out.println(" Enter your name ");
- String name = scanner.nextLine();
- if (Arrays.asList(verifiedNames).contains(name)) {
- System.out.println("dear " + name + " you are verified " +
- "you may use the lift, calling lift ");
- break; // break out of loop
- }
- }
- if (nameAttemptsLeft < 0) {
- System.out.println("Username Invalid");
- }
- break;
- case 2:
- System.out.println("option 2");
- break;
- case 3:
- System.out.println(" Please Exit Lift ");
- break;
- }
- scanner.close();
- }
- while (j < 3) {
- System.out.println("Enter your name");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement