/* svuk002@ec.auckland.ac.nz */ public class ToCapsAnswer { /* You do not need to modify the main () method */ public static void main (String[] args) { String[] testCases = { "Hello, World!", "123abc", "Oh, to live on Sugar Mountain...", "computer science 105 is fun." }; for (int i = 0; i < testCases.length; i++) { String result = convertToCaps (testCases[i]); System.out.println ("The original string was: "); System.out.println (testCases[i]); System.out.println ("The converted string is: "); System.out.println (result); } } /* Complete the convertToCaps () method below */ public static String convertToCaps (String s) { String toReturn = ""; for (int i = 0; i < s.length (); i++) { char currChar = s.charAt (i); try { if (! (currChar >= 'a' && currChar <= 'z')) throw new CapsFormatException (); currChar = (char) (currChar - 'a' + 'A'); } catch (CapsFormatException e) { System.out.println (e + " while processing " + currChar); } finally { toReturn += currChar; } } return toReturn; } }