CSC297.Java 2003F, Class 11: Implementing Vectors Admin: * Why can't Alex be on time? Too much drinking last night. * Any thoughts on how the guided reading is going? * Tell me about your word statistics programs * Homework: * Write set * Write a few more procedures (see docs for ideas) * Rewrite your word statistics program to use MyVector Overview: * Primary methods * Implementation strategy * Details of implementation * Testing (one two three) Morals from Yvonne's Example: * Be careful about array bounds * You are not required to use System.exit(0), but it's a good idea. * Helper procedures are helpful. * It's sometimes dangerous to handle lots of different exceptions at once. (Hmmm ... Sam should teach you about exceptions.) * Syntax and Semantics of compareTo. alpha.compareTo(beta) * Returns a negative number is alpha precedes beta * Returns a positive number if alpha follows beta * Returns 0 if alpha = beta Today's project: Implement Java-style Vectors * Building blocks: Arrays and fun Java techniques we know already. * Reminder: A vector is an "expandable" array. * Step one: Decide on key operations * vec.add(Object val) -- Adds to the end * vec.set(int pos, Object newVal) -- sets a value at the specified position * Something to think about vec = new MyVector(); vec.replace(5, "Hello"); * If previous values are unset, sets them to null. * vec.get(int pos) -- Get the value at a specified position * vec.length() -- Get the length of a vector * Constructor * toSTring * E.g., suppose [1,2,3] "[" + "1" + "," + "2" + "," + "3" + "]"