6098 comments
2357 subscribers
6263 on Twitter
Subscribe! Feed reader E-mail

CS21A: ArrayList

Quick 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.

Short URL: http://sachachua.com/blog/p/1731

On This Day...

  • 2013: Transcript of my chat with Mike Rohde (The Sketchnote Podcast) on digital sketchnoting — I talked to Mike Rohde about digital sketchnoting and my workflow. You can watch the podcast and check out other [...]
  • 2012: It’s okay to not know — “Congratulations! What’s your new business about?” “What will you be working on?” “So, what do you do?” I don’t [...]
  • 2011: Waking up: looking at my data — Whenever I manage to wake up early a few days in a row, I feel great about it. But I [...]
  • 2010: Patternicity, how things come together, and happiness — I’m fascinated by how things come together. When we look back, we weave almost-random elements of our lives into a [...]
  • 2009: Scaffolds and structures — I often talk about leverage and scale: creating as much value as I can for as many people as I [...]
  • 2008: You have received a painting from Sacha
  • 2007: At the social media and public relations event — I attended the Social Media and PR meetup at the Bier Market. It was great meeting people from the public [...]
  • 2007: Much progress! — I was stressing out about hooking up the back end of my metasearch engine to the front end that I’d prototyped [...]
  • 2007: Edgy — I think I left my phone in my room. At least I hope it did – my desk is a far [...]
  • 2005: Karaoke with Dave and Tony — Did most of my packing today. The big suitcase is jammed with souvenirs and the little suitcase will contain electronics. I’m shipping [...]
  • 2005: Travel plans — TKC to Kita Senju Kita Senju to Nippori (arrive by 7:00) Nippori (Keisei Line Sky Liner, 7:07) to Narita (arrive by 7:59) On [...]
  • 2005: Arrange for luggage pick-up by on the 23rd or 22nd — 1950 yen charge for 2nd piece of luggage Pickup from AOTS: 9 – 12 on the 23rd Pickup in airport: 3rd floor, [...]
  • 2004: Code for Nethack screenshots in Emacs — (defvar nethack-screenshot-file "~/.nethack-notes" "Filename to store Nethack data in.") (defun sacha/nethack-take-screenshot (caption) (interactive "MCaption: ") (save-window-excursion [...]
  • 2004: CS161 announcements — Yes, there are exemptions: 90 and above. This includes the grades from the projects. The list of exempted people will be [...]
  • 2004: Stuff Eric should check out — - Alain Chesnais (a-LAHN she-NAY) - YT Lee, head of SEAGRAPH - Barbara, in charge of organizing conferences (sponsored and in cooperation [...]
  • 2004: Chapter 2, “Editing and Navigating Java Source Code.” — Link from mparaz on pinoyjug@yahoogroups.com: http://www.sourcebeat.com/docs/Eclipse%20Live/Rev_1/Eclipse%20Live_SampleChapter.pdf
  • 2004: Instructions for wearable chording keyboards — On wear-hard@haven.org, John McKown said: http://chordite.com where you can download free instructions on how to build a wearable, chording keyboard. E-Mail from John McKown
  • 2004: eBay service — I keep getting Dear eBay Member, Dear customer, you have been billed for $15.00 recently. Please update your billing information at eBay Billing [...]
  • 2004: meetup.com — Jeremy Hogan said on open-source-now-list@redhat.com: Many of you have probably already heard of Meetup.com due to its prominence in the Democratic primaries. [...]
  • 2004: CS161: Notes on file systems — I might not be able to give a lecture on filesystems this Friday (or it might whiz past with my mile-a-minute [...]
  • 2003: blogging — I’ve been reading up on blogging, since I want to get a firm grip on the kind of software I’d like. [...]

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!