******************************************************************************* 0) Administrative - hw: 13.1-13.3 1) Last time- started arrays - what they are, how to make them - looping through them, finding things 2) Go over 10.3 and 10.5 in groups 3) Highlights A. Multi-dimensional arrays - you can make an array of arrays * draw diagram for multiplication table * draw diagram for the A5 board - there are two ways of initializing again * make the board with an initializer list * make the table with a nested loop - indexing twice means going two levels in * retrieve values from both * explain the 3 types of variables and 2 lengths - ragged arrays: when the 2nd level ones aren't the same length * work out how to make the table a triangle - could go as many levels as you want B. Passing arrays to methods - Java is pass-by-value: argument gets copied into parameter - is it more expensive to pass an array than an int? * is it more expensive to pass an object than an int? * no, because just the reference is copied - you're just tossing a link to your array, not making a new one * main method that makes array and calls min(array) * min(array) that returns minimum value in array * memory diagram - note that anyone who has a link can change the contents * set all entries to 5 * but only main can make the array go away (set to null) C. Returning arrays - you can make an array inside a method and return it (like Point) * main method with Robot[] robots, calls makeRobot() * makeRobot() that initializes and returns * memory diagram - if you declare it inside and don't return it, what happens? * garbage collection * this doesn't happen if you return b/c someone still links E. Other kinds of lists - ArrayList class: can add any kind of object to it resizes itself when it runs out of space - HashMap class: associates objects with non-int (object) indices like a phone book: one string maps to another - don't use these yet, but in the next CS class you will 4) Exercise A. Simple, specialized version of ArrayList: class SeaTurtleList - stores SeaTurtles in an array - you can add or delete them, and it resizes itself (just bigger) - look at main method to see how you'll use it B. Program skeleton handout - fill in the constructor * get array ready to hold the default number, leave empty - think about the resize method * how do you "change" the length? (make a whole new one) - think about the add method * what info do we need? (add the data member & initialize) * what if the count = the length? (call resize) * what assumptions will we make? (filled to that point) - think about the remove method * how do we take it out? (set to null, subtract number) * do our assumptions still hold? ways to fix the hole: - you could shift everyone down (maintains order) - you could patch it with the last one (do this) * if we left the hole, how would add() change? - write the find method, assuming no holes * return -1 if the turtle isn't in there * if there were holes, how would it change? C. What does the memory diagram look like at each point? 5) Summary - passing/returning arrays - multi-dimensional arrays - adding and removing things - other kinds of lists in Java *******************************************************************************