1 / 12

CompSci 100e Program Design and Analysis II

CompSci 100e Program Design and Analysis II. February 3, 2011 Prof. Rodger. Announcements. APT 0210 due next Thursday! Assignment Prestidigitation due 2/8. Debugging. What can you do when your APT/program doesn’t work? Consulting hours Get Sleep – rest those eyes Debug

bert-beck
Download Presentation

CompSci 100e Program Design and Analysis II

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. CompSci 100eProgram Design and Analysis II February 3, 2011 Prof. Rodger CompSci 100e, Spring2011

  2. Announcements • APT 0210 due next Thursday! • Assignment Prestidigitation due 2/8 CompSci 100e, Spring2011

  3. Debugging • What can you do when your APT/program doesn’t work? • Consulting hours • Get Sleep – rest those eyes • Debug • Add print statements • APTs – output right away “Starting new problem” • Add in focused output (inside a loop (if k=mulitple of 10, print) • Make it simpler – add a main and test with smallest case it doesn’t work for • Trace simple case by hand • Test each method with input and output CompSci 100e, Spring2011

  4. Assignment Prestidigitation – now due Tuesday, Feb 8 • Getting Started – no snarf • Create Java Project • Create Class file • Use previous code – cut and paste • Read in input from file • Copy data files CompSci 100e, Spring2011

  5. Sets - Operations • What operations can you do on a set? • Classwork 3 CompSci 100e, Spring2011

  6. Maps • Maps are another way of organizing data • Keys and Values • Each key maps to a value • Some keys can map to the same value • Can change the value a key maps to

  7. Example • Each student could be mapped to their favorite ice cream flavor

  8. Implementing a Map • We will use TreeMap in Java • Will also use HashMap, another implementation • Example: TreeMap<String, String> fav = new TreeMap<String,String>(); • Keys map to values

  9. To use a Map • Put in a key and its value fav.put(“Forbes”, “Strawberry”); • Get a value for a key val = fav.get(“Forbes”); • Change value for key fav.put(“Astrachan”, “Coffee Mocha”); • Get all the keys as a set Treeset<String> ky = fav.keyset();

  10. Change Astrachan’s value

  11. Value could be a set

  12. Let’s go back to ClassScores • Find all the modes in an array of ints • This time solve it using a map CompSci 100e, Spring2011

More Related