

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Hanks; Class: Intro to Programming in Java; Subject: Computer Science Info Systems; University: Fort Lewis College; Term: Unknown 1989;
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Homework Due Sept 26. Show students my version. Ask if there are any questions? Coding Standard! Reading: Chapter 4: 4.1 through 4.8 (you can skip 4.7.2 and 4.7.3) Last time: Collections What’s a collection?
It maintains the order of the items. We can retrieve the items in the same order as we added them. It can be used to store objects of any type (but not primitives!) Look back at the Notebook source – it looks pretty simple, as it contains only 1 instance variable. All the difficult work is done in the ArrayList – this is one of the great advantages of using library classes: someone else has taken the time to develop something useful, and we can use it. Discuss Notebook constructor, storeNote, and numberOfNotes methods. Point out that the Notebook doesn’t keep track of the number of notes – it lets the ArrayList do that instead. Numbering with collections Each item in a collection can be accessed individually using its index , or position in the list. What was something important about indexing? Indices are numbered from 0 to listSize -
Look at the showNote method – most of the code is there to make sure that you don’t try to access the ArrayList outside of its valid range. Accessing all of the elements in an ArrayList – The while statement Ok, so we can create a Notebook, add Notes to it, and display the individual Notes. What would I need to do to access display all of the Notes in the Notebook? We could just call showNote(0), showNote(1), showNote(2), … What’s wrong with this approach? We need some sort of repetitive (iterative) operation: a loop Java provides some looping statements – one of these is the while statement. while ( boolean-expr ) { statements; } The while statement works this way: