123456789101112131415161718192021222324252627282930313233343536 |
- // JN - 2018
- import java.util.Scanner;
- public class Main {
- public static void main() {
- int i = 5;
- start("Enter a name, " + i + " attempts.", i);
- }
-
- public static void start(String greeting, int i){
- System.out.println(greeting);
- Scanner kb = new Scanner(System.in);
- String userInput = kb.nextLine();
- kb.close();
- aliceOrBob(userInput, i);
- }
-
- public static void aliceOrBob(String name, int i) {
- String message = name.equals("Alice") || name.equals("Bob") ?
- "Hello " + name
- :
- "err";
- if (i == 1) {
- System.out.println("Out of attempts");
- return;
- }
- if (message.equals("err")) {
- i--;
- start("Try a new name, " + i + " attempts remain.", i);
- } else {
- System.out.println(message);
- Person valid = new Person(name);
- return;
- }
- }
- }
|