Algorithms and Data Structures
Quick Links
What's New 
Course Book 
Java Book 
ToDo Lists (doing something with a generic list) 
In the previous notes we introduced a generic List of objects. We now use this to implement a ToDo list. That is a list of things we have to do (I've got a button for this on my PalmPilot). 

A ToDo item typically has a priority, a description, and an identification number (so I can say, get me item with id=327 for example). 

We therefore want to hold these ToDo items on a list, and keep them in priority order. We make the assumption that low numbers correspond to high priority. I'm going to use the generic List (as you'd expect). 

The first thing I must do is define the class. I need to define the instance and class variables, the constructor methods, a toString method (so that I can print it), and accessor functions (to get the protected instance variables). 

Second, I must define the classes for doing comparisons between ToDo items, with respect to maintaining order. I also need to define the Predicate for testing if a ToDo item has what we are after (in this case a matching identification number). 

Finally, I need my environment for running it all, Test environment. This creates a List and then allows us to add, delete, insert ToDo items, and much more. 

Source Code 

Copyright © Patrick Prosser 1999.