1 / 12

Some Practice Free Response Problems

Some Practice Free Response Problems. (For CS III AP) March – April 2014. Some tips for these Problems…. Focus on what you need to return in each method Don’t neglect to read the class( es ) on which the problem relies Use the Given Appendix when Needed

mills
Download Presentation

Some Practice Free Response Problems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Some Practice Free ResponseProblems (For CS III AP) March – April 2014

  2. Some tips for these Problems… • Focus on what you need to return in each method • Don’t neglect to read the class(es) on which the problem relies • Use the Given Appendix when Needed • (A Better solution is to Memorize the methods for Array, String, Actor, etc.) • Practice makes Perfect

  3. Ex 1: What We’re Given…

  4. What We’re Given…(cont.) public class StringCoder { private String masterString; /** @param master the master string for the StringCoder * Precondition: the master string contains all the letters of the alphabet */ public StringCoder(String master) { masterString = master; } /** @param parts an ArrayList of string parts that are valid in the master string * Precondition: parts.size()> 0 * @return the string obtained by concatenating the parts of the master string */ public String decodeString(ArrayList<StringPart> parts) { /* to be implemented in part (a) */ } This is what you code

  5. Part A: One Solution String result = new String (“”); for (intind = 0; ind < parts.size(); ind ++) { StringPartthisUnit = parts.get(ind); result += masterString.substring (thisUnit.getStart(), thisUnit.getStart()+thisUnit.getLength()); } return result;

  6. Part B /** @paramstr the string to encode using the master string * Precondition: all of the characters in str appear in the master string; * str.length() > 0 * @return a string part in the master string that matches the beginning of str . * The returned string part has length at least 1. */ private StringPartfindPart(String str) { /* implementation not shown */ } /** @param word the string to be encoded * Precondition: all of the characters in word appear in the master string; * word.length() > 0 * @return an ArrayList of string parts of the master string that can be combined * to create word */ public ArrayList<StringPart> encodeString(String word) { /* to be implemented in part (b) */ } // There may be instance variables, constructors, and methods that are not shown. }

  7. Part B: One Solution String remaining = word; int limit = word.length(); intcurrentInd = 0; ArrayList<StringPart> units = new ArrayList<StringPart>(); while (currentInd < limit) { StringPartthisUnit = findPart (remaining); currentInd += thisUnit.getLength(); remaining = remaining.substring (thisUnit.getLength()); units.add (thisUnit); } return units; ← Could just as easily be (!remaining.equals(“”))

  8. Another Interesting Free Response Problem… • 2011 AB #4 – Using a 2-D array and Strings 

  9. Part A: One Solution private void fillBlock (String str) { if (str.length() > numRows*numCols) { for (int row = 0; row < numRows; row++) { for (intcol = 0; col < numCols; col++) { letterBlock[row][col] = str.substring (numRows*row + col, numRows*row + col+1); } } } else { for (int row = 0; row < numRows; row++) { for (intcol = 0; col < numCols; col++) { if ((str.substring (numRows * row + col, numRows * row + col + 1).equals (“”))) { letterBlock[row][col] = “A”; } else { letterBlock[row][col] = str.substring (numRows * row + col, numRows * row + col + 1); } } } } }

  10. Part B

  11. Thank you very much • Please come next week with your solution(s) • We will check back then • Let me know if you have any questions • This ppt will be posted (like the last one) • At http://mthcompsci.wordpress.com/ • With some other sources for Free Response Questions • See you next week! Good luck.

More Related