CS305J Fall 2007 Final 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. Answer as shown or -1. If mistake on data type, error carried forward to next answers. 1. 13 2. 2 3. "3UT" 4. 1.0 5. 1.5 6. 2 7. "Long52" 8. false // on booleans differences in capitalization okay 9. true 10. false 2. 0.5 point each. No error carried forward. result == -1 i < nums.length nums[i] > tgt result == i Point A A S X N Point B A A S N Point C N A A A Point D S A S S Point E S N X S 3. Suggested Solution: public static boolean okToRide(int temp, int timeOfDay, boolean isRaining){ boolean result = false; if( 6 <= timeOfDay && timeOfDay <= 18){ if(!isRaining && 30 < temp && temp < 110) result = true; else if(isRaining && 70 < temp && temp < 115) result = true; } return result; } Different answers acceptable if they work. check time of time in bounds, attempt: 1 point, correct 3 points check temp when not raining, attempt 1 point, correct 2 points check temp when not raining, attempt 1 point, correct 2 points return answer 1 point 5. Suggested Solution: public class Badger implements Critter{ private static final int[] WEAPONS = {Critter.ROCK, Critter.PAPER, Critter.SCISSORS}; private Color myColor; private int numFights; private int weapon; public Badger(){ double r = Math.random(); if( r < 0.6 ) myColor = Color.BLACK; else if( r < 0.9 ) myColor = Color.GRAY; else myColor = Color.WHITE; numFights = 3; } public Color getColor(){ return myColor; } public int getMove(CritterInfo info){ return Critter.NORTH; } public String toString(){ String result = ""; if(myColor == Color.BLACK) result = "B"; else if(myColor == Color.GRAY) result = "G"; else result = "W"; return result; } public int fight(String opponent){ if(numFights == 3){ numFights = 0; weapon = WEAPONS[(int)(Math.random() * 3)]; } numFights++; return weapon; } } Criteria: class header: 1 point instance variables private: 1 point instance variable for color: 1 point instance variable for weapon: 1 point instance variable for number of fights: 1 point constructor: 3 points, 1 point attempt, 2 point correct getColor: 1 point getMove: 1 point toString: 3 points, 1 point attempt, 2 point correct fight: 2 points, 1 point attempt, 1 point correct Don't take off for minor syntax errors. (semicolons, braces)