Problem #1: 2 pts each, 1 pt for correct value of wrong type (missing parens, no .0) Problem #2: 1 pt 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: -2 if columns transposed each is 3 pts, -1 for a single number wrong or for a single transpose Problem #4: -3 if fibonacci sequence is one off (e.g., 1, 1, 3, 8) Problem #6 Solution: public static int quadrant(double x, double y) { if (x > 0 && y > 0) { return 1; } else if (x < 0 && y > 0) { return 2; } else if (x < 0 && y < 0) { return 3; } else if (x > 0 && y < 0) { return 4; } else { // at least one equals 0 return 0; } } 2 correct header (void okay if no return, -1 per error, int/int vs double/double types for x and y is one error) 3 they return the values they compute 2 most of the time 1 always 10 five different cases 2 quadrant 1 (x > 0 && y > 0) 1 attempt (specifically try to test for this case) 1 correct (correct test, always returns 1 in this case) 2 quadrant 2 (x < 0 && y > 0) 1 attempt (specifically try to test for this case) 1 correct (correct test, always returns 2 in this case) 2 quadrant 3 (x < 0 && y < 0) 1 attempt (specifically try to test for this case) 1 correct (correct test, always returns 3 in this case) 2 quadrant 4 (x > 0 && y < 0) 1 attempt (specifically try to test for this case) 1 correct (correct test, always returns 4 in this case) 2 quadrant 0 (x == 0 || y == 0) 1 attempt (specifically try to test for this case) 1 correct (correct test, always returns 0 in this case) ** Special Cases ** -1 if return a String instead of int (can get header return type if it returns String) -1 per swap e.g. if quadrant 4 and 2 are backwards -1 for 1's instead of 0's -1 for <= or >= -2 scope issues Problem #7 Solution: public static void printTwoDigit(Random r, int n) { boolean seen42 = false; for (int i = 1; i <= n; i++) { int number = r.nextInt(90) + 10; System.out.println("next = " + number); if (number == 42) { seen42 = true; } } if (seen42) { System.out.println("We saw a 42"); } else { System.out.println("no 42"); } } 1 header 4 for loop 2 attempt 2 correct (-1 if OBOB) 3 choosing random 2-digit number 1 attempt 2 correct (-1 if OBOB) 2 println inside the loop to print 2-digit number 1 attempt 1 correct 5 Did we see a 42? 1 two printlns ("We saw a 42" and "no 42") 2 some kind of flag or counter variable that is updated when 42 is seen (exception: -1 for small mistakes, such as checking for 24 instead of 42) 1 correct initialization of that counter/flag 1 counter/flag variable used correctly with an if/else or if/if after the loop to choose between the two printlns -1 for incorrectly using Random object Problem #8 Solution: public static int digitsInARow(int n) { int count = 1; int last = -1; int max = 1; while (n > 0) { if (n % 10 == last) { count++; } else { count = 1; } if (count > max) { max = count; } last = n % 10; n = n / 10; } return max; } Plus criteria (max +4) 1 header 2 loop that uses n/10 and n%10 to pull apart the digits of a number 1 attempt 1 correct 1 counter variable with at least 2 of: initialized to 0 before loop attempt to increment inside loop returned after loop ------------------------------------------------------------------------------- Minus Criteria (min of 5) To grade this way, you have to see a loop that pulls apart digits and a counter AND a reasonable attempt to compare adjacent digits. These include: storing a prev digit to compare against checking to see if last 2 digits are divisible by 11 checking to see if (ones digit == tens digit) When in doubt, pass along a solution for minus grading. Minus grading starts at 9 and works down, never going below 5. -1 for minor error (bad initialization, forgot to return) -2 for medium error (printing result rather than returning, doesn't handle sequences at end of number) -3 for major error (counts all occurrences of a digit vs "in a row") -4 if no max computation (counts all digit matches or counts last match)
Stuart Reges
Last modified: Fri Sep 16 15:55:02 PDT 2011