CS21A: ArrayList
| -UncategorizedQuick review: arrays
Arrays are a neat way to store a fixed number of items. You can
declare and create arrays and loop over them. They’re perfect for
board games and other applications where you know exactly how many
items you’ll need to store.
EXERCISE: (Due 11:59:59 PM Sunday)
Download http://sacha.free.net.ph/notebook/cs21a/address.zip and unzip
it into a convenient directory. Open the HTML file and run it in
JCreator, or open a command prompt and type “appletviewer
address.html”. (If it gives you “Command not found”, try
“c:\j2sdk1.4.2_02\bin\appletviewer address.html”.
E-mail your answers to me by the specified time.
– Put 0 in the index field and a name in the name field. Press Set.
Put 1 in the index field and a different name in the name field.
Press Set. Put 0 in the index field and press Show. What happens?
Put 1 in the index field and press Show. What happens? (Note that
the data doesn’t get saved to the hard disk – you’ll learn how to do
that in CS21B!)
– What is the largest number that you can use in the index field
without getting an error?
– What is the smallest number that you can use in the index field
without getting an error?
– How many items can this simple address book store?
– As practice in applets, components, layouts and arrays, write your
version of this applet (ReallySimpleAddressBook). It should look
like this applet and behave exactly like this applet. (5 points)
– As practice in objects and arrays of objects, create a Person class.
The Person class should have a name attribute and a phone attribute
(both Strings), and it can have any methods you want. Make a
SimpleAddressBook applet that has a “Phone:” field after the Name:
field. It should set and show this as well as the name. Instead of
having two separate arrays for name and phone (you might forget to
update one of them – I do that all the time!), use just one array of
Person objects. (5 points)
– Make a SearchableAddressBook applet. Add a “Search by name” button.
When pressed, you should display the first record whose name equals
the one in the name field. NOTE: Use .equals(…) instead of == to
compare strings. You can also use .equalsIgnoreCase(…) if you want
“ABC” to be considered the same as “abc”. (5 points)
You may ask other people for help as long as you type and understand
your entire submission.