123456789101112131415161718192021222324252627282930313233343536
  1. // JN - 2018
  2. import java.util.Scanner;
  3. public class Main {
  4. public static void main() {
  5. int i = 5;
  6. start("Enter a name, " + i + " attempts.", i);
  7. }
  8. public static void start(String greeting, int i){
  9. System.out.println(greeting);
  10. Scanner kb = new Scanner(System.in);
  11. String userInput = kb.nextLine();
  12. kb.close();
  13. aliceOrBob(userInput, i);
  14. }
  15. public static void aliceOrBob(String name, int i) {
  16. String message = name.equals("Alice") || name.equals("Bob") ?
  17. "Hello " + name
  18. :
  19. "err";
  20. if (i == 1) {
  21. System.out.println("Out of attempts");
  22. return;
  23. }
  24. if (message.equals("err")) {
  25. i--;
  26. start("Try a new name, " + i + " attempts remain.", i);
  27. } else {
  28. System.out.println(message);
  29. Person valid = new Person(name);
  30. return;
  31. }
  32. }
  33. }