CS305j Fall 2007 Midterm 1 Key, Suggested Solutions, and Grading Criteria Abbreviations: NAP - no answer provided ECF - error carried forward OBOE - off by one error BOD - benefit of the doubt GCE - misunderstood question. Answer is way off base. 1. "3ut4" 9 4 5.0 "cs6ie" 8.5 3 points per answer. missing quotes was -1 for first instance 5 instead of 5.0 was -1 Some error carried forward was given if a student showed their work and it was clear where the mistake was. Most mistakes were due to errors in order of operations or not realizing if an operation was floating point or int. 2. 3 6 5 9 2 3 points each Students did very well on this tracing question for the most part. Most parts were independent so there was not the chance for error carried forward. 3. loop(-1): 0 loop(1): 2 loop(2): 4 3, 3, and 4 points respectively. A large number of students thought loops(-1) would be a problem. If the parameter is -1 the for loop simply does not execute. (In other words it executes zero times.) This simply returns 0. Some errors in initial value of result. 4. The drawing panel would look a lot like a bulls eye. For circles centered around the middle of the drawing panel. Each circle getting smaller. 2 lines that form a cross, not an x. Break down of points. some circles 2 points 4 circles 2 points circles nested inside each other getting smaller 2 points circles concentric on the middle of drawing panel 2 points lines correct 2 points 5. 1-1111 1-2-222 1-2-3-33 1-2-3-4-4 Lots of mistakes on this one. Students has to have the structure correct and the right values. A lot of students put in i and j instead of the ints stored inside i and j. A minority of students thought there was a syntax error. There was an unusually placed brace due to formatting issues, but the code did not have a syntax error. I will not purposefully waste more than 10% of a test on a syntax error. Some students also thought redeclaring j was a syntax error, but it isn't the scope of the first j ends at the end of the for loop where it is declared. 6. Solution 1 public static int expectedWins(int games, int runsScored, int runsAllowed){ double num = runsScored * runsScored; double denom = num + runsAllowed * runsAllowed; int result = (int)Math.round( games * num / denom ); return result; } Solution 2 public static int expectedWins2(int g, int rs, int ra){ return (int)(Math.round( g * (1.0 * rs * rs) / (rs * rs + ra * ra))); } Header correct 3 points Parameters correct 2 points (-1 for poor identifier names) calculation correct 7 points rounded solution 2 points return 1 point A large number of students had a mistake in the calculation. Something must be done to ensure the division is floating point division, not int division. A large number of students failed to do this. If your exam has "double -2" that means you did not correctly ensure the division was floating point. 7. Suggested Solution public static void printLines(int numLines){ int val = 1; for(int i = 1; i <= numLines; i++){ for(int j = 1; j <= i; j++){ System.out.print(val + " "); val++; } System.out.println(); } } Header 2 points parameter 2 points variable to track number to print out 2 points outer loop correct 5 points inner loop correct 5 points correct print of number and space 2 points correct println placement 2 points No consistent problems, just lots of little ones.