/* 5.uge Exercise 15: Guess my name Author: Lasse Lerkenfeld Jensen */ import cs1.Keyboard; public class GuessMyName { private static String name = "bartsimpson"; public static void main(String[] a) { String guess = "", positionText = ""; int position; System.out.print("Guess my name:"); while (true) { guess = Keyboard.readString(); position = guess.compareToIgnoreCase(name); if (position == 0) // correct name { System.out.print("You guessed my name, my name is "+name); return; } //wrong name System.out.println("My name is absolutely not " + guess + "!"); if (position < 0) positionText = "after "; else positionText = "before "; System.out.print("My name is "+positionText+guess+" in the alphabet!\nTry again: "); } } }