public class Telephone { /* This application lets a user enter a letter from the telephone \ and returns the corresponding number. */ public static void main(String args[]) { String letter; char aChar; String prompt="Enter a letter on the telephone (Q or Z to quit):"; System.out.print(prompt); letter = Keyboard.in.readString(); if (letter !=null) aChar = letter.toUpperCase().charAt(0); else aChar=' '; while ((aChar != 'Q') && (aChar != 'Z')) { if ("ABC".indexOf(aChar) != -1) Telephone.report(aChar, 2); else if ("DEF".indexOf(aChar) != -1) Telephone.report(aChar, 3); else if ("GHI".indexOf(aChar) != -1) Telephone.report(aChar, 4); else if ("JKL".indexOf(aChar) != -1) Telephone.report(aChar, 5); else if ("MNO".indexOf(aChar) != -1) Telephone.report(aChar, 6); else if ("PRS".indexOf(aChar) != -1) Telephone.report(aChar, 7); else if ("TUV".indexOf(aChar) != -1) Telephone.report(aChar,8); else if ("WXY".indexOf(aChar) != -1) Telephone.report(aChar, 9); else { System.out.println("Invalid letter."); } System.out.print(prompt); letter = Keyboard.in.readString(); if (letter !=null) aChar = letter.toUpperCase().charAt(0); else aChar=' '; aChar = letter.charAt(0); } System.out.println(); System.out.println("Have a nice day!"); } private static void report (char aChar, int value) { System.out.print("The letter " + aChar + " corresponds to "); System.out.print(value); System.out.println(" on the telephone."); System.out.println(); } }