public class firsthwk { public static int nameCheck (char[] names) { // Effects: samples a list of names and counts how many blanks int blankCount = 0; for (int i = names.length; i > 1; i--) { if (names[i-1] == ' ') { blankCount++; } } return blankCount; } // Run one test, print and check results private static void runTest (int testNum, char[] testIn, int expectedOut) { int actualOut; actualOut = nameCheck (testIn); System.out.print ("Test #" + testNum + ", num blanks: " + actualOut + " ... expected output: " + expectedOut); if (actualOut != expectedOut) System.out.print (" *** FAILURE ***"); System.out.println (); } // Test harness for nameCheck() public static void main (String args[]) { int expectedOut; // Test driver -- method calls to nameCheck() // three blanks at the beginning char arr1 [] = {' ', ' ', ' ', 'c', 'd'}; expectedOut = 3; runTest (1, arr1, expectedOut); // A blank in the middle and at the end. char arr2 [] = {'a', 'b', ' ', 'c', ' '}; expectedOut = 2; runTest (2, arr2, expectedOut); // No elements char arr3 [] = {}; expectedOut = 0; runTest (3, arr3, expectedOut); // Null array // (Does not compile under Java 1.5) // char arr4 []; // expectedOut = 0; // runTest (4, arr4, expectedOut); } }