Week 3: week of Sept 10 More loops: Notebook example: Notebook1: demo of storeNote, numberOfNotes, showNote look at code: ArrayList get/size inspector Problem: what if we forget which note we want? Notebook2: A *loop* to show all notes while version for-each version (for loop, or "classic for loop", is also a possibility) Where else would this help? LabClass project Wednesday: Look at LabClass for:each versus while loops in Notebook ============================================================ LabClass: add a check against duplicates. if (searchStudent(newStudent.getStudentID())) { System.out.println("Student with ID " + newStudent.getStudentID() + " already enrolled"); return; } else { ============================================================ for:each loop versus while loop: int totallen = 0; for(String note : notes) { totallen += note.length(); } While loop: int totallen = 0; int n = 0; while (n loops: howManyMailItems(string who) for:each loop getNextMailItem(String who): Iterator loop in original version; could also be while loop do the while version forgot i++ used <= instead of < demo of reading messages, and watching the inspector view change Demo of sending a message and setting a breakpoint in printNextMessage(), and running the debugger. (This crashed a couple times for me) 5. Class diagrams v object diagrams class arrow: NOT just for subobjects What do the arrows mean for object diagrams? "Uses" relationship ================================================== Notebook search loop javadoc and String page; find note.contains(s) "return loop": use return statement to terminate when found isPrime was an example of this so was LabClass.searchStudent "print all" loop: terminate at end of list, regardless of data found Notebook.searchNotes is an example "find first" loop: compare to example on page 94 ==================================================