CSC153 2004S, Class 44: Implementing Lists with Nodes (Linked Lists) Admin: * Today's prospective: * Jesse, WV, Dartmouth et al., Open Source * Saul's personal hero speaks tonight at 8:30 * Saul says "I know I'm going to be there tonight." * Saul says "He is a beacon of hope in these dark times." * Saul says "He is a voice of hope for all that is right and good in the world in this wilderness of fascistic liberal wishiwashiness." * Yes, "fascistic" is a word with a subtly different meaning from "fascist" * Thanks for Friday * Questions on the exam? * Purpose of interfaces? * Polymorphism: You can build methods that use the interface as a parameter type; You can call these methods with any class that implements them * Helpful example one: GeneralizedList * Sometimes it doesn't make sense to implement anything when you're talking in generalities * Given that mayPrecede is already associated with Orderable, why do we need a separate mayPrecede for Orders, given that it will be applied to Orderable objects? * Reponse: What are the normal parameters to an order's mayPrecede? * Orders can order orderable objects in a different way than the default. * Orders can order objects that have no default orders * How do you print a double to only a certain number of decimal points? * It's obvious: Read the documentation for java.text.DecimalFormat. * Convert to a string, find the decimal point, and then take a substring * Multiply by 100, truncate, and do some more crap * Implement your own doubles * Which methods should I evaluate for their exceptional characteristic? (That is, when you say "Which of the methods above might throw an exception?", which methods do you mean?) * Orderable.mayPrecede, Order.mayPrecede, Addable.add * Most Orders are not Orderable * If we are calling a method (like an array index) that throws an Exception, do we have to throw a separate exception? * No * You can't write, can you? * No. * How do I implement a sorting algorithm? * public void sort(Order order, DynamicArray stuff) * E.g., sort(new OrderStudentsByAnnoyingnessDecreasing(), myCSC153) myCSC153.dropFirst(); // Bye .... myCSC153.dropFirst(); // Bye .... * What was the thesis of "Lists with current considered harmful"? Overview: * Detour: Implementing isValid * Linked lists: Implementing lists with nodes. * Implementing basic methods * Implementing ordered methods * Cool tricks