SUNY Geneseo Department of Computer Science


Introduction to Lists

{Date}

CSci 141, Spring 2004
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Misc

Amendments to student association constitution need your vote

Updated versions of

Exam 2 will be next Thursday (April 1)

Questions?

Saving lists - save in internal binary format

Exceptions?

        double divide( x, y ) throws InvalidArgumentException
            if y != 0
                return x / y
            else
                throw new InvalidArgumentException()
        main() {
            try {
                double a = divide( x, 0.0 );
                print a
            }
            catch ( InvalidArgumentException e ) {
                print "I'm a fool! y = 0"
                System.out.println( e );
            }
            catch ( Exception e ) {
                System.out.println( "D'Oh!" );
            }
        }

[Exception has Subclasses RuntimeException (with subclass NullPointerException), IOException, etc.]

        class MyException extends Exception {
            public MyException( String desc ) {
                super( desc );
            }
        }
        ...
        throw new MyException( "User Error" );

Reading files:

Lists

Section 11.1 through Section 11.3.1

Example list algorithms

        // In a subclass of List:
        Object second() {
            return this.getRest().getFirst();
        }

Next

Continue looking at list algorithms

Mini-Assignment

        // In some subclass of List...
        public void delete( Object x )
            ...
        // Postcondition: List contains no items equal to x.

Next Lecture