Grading acronyms OBOE - Off by one error. Calculation is off by one. AIOBE - Array Index out of Bounds Exception will occur NPE - Null Pointer Exception will occurs ABA - Answer by Accident GCE - Gross Conceptual Error. Did not answer the question asked or showed fundamental misunderstanding NAP - No answer provided. No answer given on test ECF - Error carried forward. BOD - Benefit of the Doubt. Not certain code works, but, can't prove otherwise Gacky - Code very hard to understand even though it worksCS305J - Fall 2006 - Midterm 2 Suggested Solutions and Criteria The basic break down of points per section is only a guide and the instructor and graders may have taken off more points for particularly bad attempts. 1. Answers: {12} {3, 8} {6, 7, 12} {-2, -1, -3, -1} 3 points each. line. If some elements incorrect partial credit. If grader could determine what person did wrong carry the error forward and only take off for the first mistake. 2. Suggested Solutions: // lower <= upper // there will be at least one element of data that is in range public static int averageOfValuesInRange(int[] data, int lower, int upper){ int total = 0; int num = 0; for(int i = 0; i < data.length; i++){ if(data[i] >= lower && data[i] <= upper){ total += data[i]; num++; } } return total / num; } 20 points total. if it works, full credit. minor syntax problems not penalized 2 points define / init local vars loop through data 2 points attempt 4 points correct test each element in data to see if it is in range 2 points attempt 4 points correct update variables 2 points variable for total of elements 2 points variable for number of elements in range 2 points calculate and return value correctly 3. Suggested solutions public static boolean toughOpponent(int wins, int losses, boolean atUT) { double winPercent = 1.0 * wins / (wins + losses); return (atUT && winPercent >= .85) || ( !atUT && winPercent >= .75); } public static boolean toughOpponent(int wins, int losses, boolean atUT) { double winPercent = 1.0 * wins / (wins + losses); return (winPercent >= .85) || ( !atUT && winPercent >= .75); } public static boolean toughOpponent(int wins, int losses, boolean atUT) { double winPercent = 1.0 * wins / (wins + losses); boolean result = false; if( atUT && winPercent > 0.85 ) result = true; else if( !atUT && winPercent > 0.75 ) result = true; return result; } 20 points total. if it works, full credit. minor syntax problems not penalized 3 points for attempting to calculate win percentage 2 points for correctly calculating win percentage. (-1 for int division) 3 points for attempting handle case when at UT 3 points for correctly handling case when at UT 3 points for attempting handle case when not at UT 3 points for correctly handling case when not at UT 3 points for returning a result / value minor errors on correctness can lose just 1 or 2, not all 3. 4. Suggested Solution public static String triple_abi(String org){ String result = ""; char c; for(int i = 0; i < org.length(); i++){ c = org.charAt(i); if( c == 'a' || c == 'b' || c == 'i') result = result + c + c + c; else if( c != '-') result = result + c + c; } return result; } 20 points total. if it works, full credit. minor syntax problems not penalized 2 points local variable for resulting String loop through original String 2 points attempt 3 points correct 2 points correctly access the current char (1 method call and local var or repeated method calls) 3 points identify characters equal to a, b, or i 3 points add 3 characters to result 3 points identify characters equal to a, b, or i 3 points add 3 characters to result 3 points identify all other non dash characters 3 points add 2 characters to result 2 points handle dashes correctly 1 point return result 5. The method is not very general because the characters to triple and remove are hard coded. The number of times to repeat the given characters is also hard coded. Parameters should could be used to generalize this: public static String tripleSomeIgnoreOthers(String original, char[] charactersToIncrease, int amountToIncrease, char[] charactersToRemove); Or words to that effect. 6. Suggested Solutions. Note there were many possible solutions. A very common error was if there wee two values equal to target in a row, student's solutions failed. public static void moveTargetToBack(int[] data, int tgt){ int[] result = new int[data.length]; int posAtBack = data.length - 1; int numFound = 0; for(int i = 0; i < data.length; i++){ if( data[i] == tgt){ result[posAtBack] = tgt; posAtBack--; numFound++; } else { result[i - numFound] = data[i]; } } for(int i = 0; i < data.length; i++) data[i] = result[i]; } // very nice alternate solution public static void moveTargetToBack2(int[] data, int tgt){ int numNotEqualTarget = 0; for(int i = 0; i < data.length; i++){ if( data[i] != tgt){ data[numNotEqualTarget] = data[i]; numNotEqualTarget++; } } // fill in the right number of values equal to target for(int i = numNotEqualTarget; i < data.length; i++) data[i] = tgt; } // common attempted solution // DOES NOT WORK IF THERE ARE CONSECUTIVE TGTs public static void moveTargetToBack3(int[] data, int tgt){ for(int i = 0; i < data.length; i++){ if( data[i] == tgt){ // shift elements to front for(int j = i; j < data.length - 1; j++){ data[j] = data[j+1]; } data[ data.length - 1 ] = tgt; } } } // Corrected version of the shift elements approach public static void moveTargetToBack3(int[] data, int tgt){ int numEqualTgt = 0; int i = 0; while( numEqualTgt + i < data.length){ if( data[i] == tgt){ // shift elements to front for(int j = i; j < data.length - 1; j++){ data[j] = data[j+1]; } data[ data.length - 1 ] = tgt; numEqualTgt++; } else i++; } } 22 points total. if it works, full credit. minor syntax problems not penalized loop through array of ints 2 points attempt 2 points correct identify elements equal to target 2 points attempt 2 points correct move values equal to target to end 3 points attempt 4 points correct move values not equal to target to front and maintain relative order 3 points attempt 4 points correct