Problem #1: 2 points each, 1 point for correct value of wrong type (missing parens, no .0) Problem #2: 1 point for each of the 12 values -1 if any error in surrounding text (dittos not allowed) -4 if two columns transposed -8 if you need to transpose twice Problem #3: each is 3 points, -1 for a single number wrong or for a single transpose -2 if columns transposed -2 if formatting error (e.g., commas between numbers) -1 if reversed -0 if output is quoted -0 if underscore for space Problem #4: column 1 is 1 point, column 2 is 2 points -2 if columns transposed -2 if formatting error (e.g., commas between numbers) -0 if output is quoted -0 if underscore for space Problem #5: 1 point per blank Problem #6 Solutions: public static boolean hasOddEven(int x, int y, int z) { return x % 2 != y % 2 || y % 2 != z % 2; } public static boolean hasOddEven(int x, int y, int z) { if (x % 2 == 0 && y % 2 == 0 && z % 2 == 0) { return false; } else if (x % 2 == 1 && y % 2 == 1 && z % 2 == 1) { return false; } else { return true; } } 3 correct header (-1 per error) 1 return something somewhere 3 three mods (x % 2, y % 2, z % 2) in a meaningful context like an if, a sum, a comparison, a boolan expression with && or || (1 point for each) 8 cases eee case <- 2 points ooo case <- 2 points eeo case eoe case eoo case oeo case ooe case oee case 2 determines false when all even based on complete tests 2 determines false when all odd based on complete tests 2 determines true in at least 2 of the mixed cases based on tests 2 determines true in all 6 of the mixed cases based on tests special cases -2 if they return the negation of the right answer -4 if we can make a single transformation to their code that gets them a higher score (e.g., adding parentheses) Problem #7 Solution: public static void findRange(Scanner console) { System.out.print("number (0 to quit)? "); int number = console.nextInt(); int max = number; int min = number; while (number != 0) { if (number > max) { max = number; } else if (number < min) { min = number; } System.out.print("number (0 to quit)? "); number = console.nextInt(); } int range = max - min; System.out.println("range = " + range); } 1 correct header (non-void return okay if they return something of that type) 2 loop while number != 0 1 attempt 1 correct 3 prompt and read number inside loop 2 attempt -- prompt and console.nextInt() somewhere 1 correct -- print, correctly prompts and stores (doesn't read twice) 1 idea: some attempt at max/min computation 2 max computation 1 max declared/initialized properly outside loop 1 max updated correctly in loop 2 min computation 1 min declared/initialized properly outside loop 1 min updated correctly in loop 2 handles terminating 0 correctly 2 correctly print what they think is the range after loop (no double jeopardy if they didn't use a max/min approach) 1 attempt 1 correct Problem #8 Solutions: public static String undouble(String s) { String result = ""; if (s.length() > 0) { char last = s.charAt(0); result += last; for (int i = 1; i < s.length(); i++) { if (s.charAt(i) != last) { result += s.charAt(i); } last = s.charAt(i); } } return result; } public static String undouble2(String s) { String result = ""; if (s.length() > 0) { result = s.substring(0, 1); for (int i = 1; i < s.length(); i++) { if (s.charAt(i) != s.charAt(i - 1)) { result += s.charAt(i); } } } return result; } Can get up to 3 points for any of the following good things: 1 correct header 1 for loop involving s.length 1 returning a String 1 s.charAt(i) or s.substring(i, i + 1) 1 str += charAt or substring 1 comparing charAt(i) with charAt(i + 1) (or substring) If both of the last two (concat & adjacent comparison), then give to Stuart to grade for score of 4-9. -1 if fails on empty string or case like ccaatt -2 if their code doesn't handle 1st/last char properly -0 String result = s.charAt(0); -0 for String new = ... (reserved word)
Stuart Reges
Last modified: Fri Sep 16 15:55:25 PDT 2011