CS302 Fall 2012 Exam 2 Solution // Part II: #1 Write a code fragment that replaces Wisc. or Wis. with WI //assume city references a city, state and zip code // for example "Windsor, Wis. 53598"; String WI = "WI "; String S = "Wis. "; if ( city.contains(S) ) { int i = city.indexOf(S); city = city.substring(0,i) + WI + city.substring(i+S.length()); } S = "Wisc. "; if ( city.contains(S) ) { int i = city.indexOf(S); city = city.substring(0,i) + WI + city.substring(i+S.length()); } // Part II: #2 Complete the update(double t) of the Ship class. public void update( double t ) { if ( ! destroyed ) { updatePosition(t); if ( getPosition().getY()-getRadius() <= 0 || getPosition().getY()+getRadius() >= Config.GAME_HEIGHT-1 ) { setRotation( -getRotation() ); } if ( getPosition().getX()-getRadius() <=0 || getPosition().getX()+getRadius() >= Config.GAME_WIDTH-1 ) { destroy(); } } }