LECTURE NOTES 1 DECEMBER 2004 ASSIGNMENTS 6:00 PM Assignment 5 Design Fri 12/3 CodeLab #12 Wed 12/15 Assignment 5 Code ASSIGNMENT 4 DISCUSSION - grading questions? - BufferedReader connected to System.in - no reason to ever have more than one of these - can declare a single one to be shared by your whole program - can cause correctness problems - limited capacity: ArrayList - looping: - no loop - calls to the start() / main() method - references to objects are shared: applicability to arrays - testing strings for equality: equals() versus == - accessing a character in a string: charAt (vs. StringTokenizer) - StringTokenizer - initialize with delimiter - prompt for second argument: v(iew), a(dd), t (frequency), d(elete), c(har per word) - words can be any kind of ASCII character: includes caps and numbers - errors are logical, not necessarily compile: - nothing wrong (to readLine) if user enters v a - that is a command line error - be precise when following the specs: lots of failed testcases b/c error messages didn't match exactly - incremental development - concept questions? ABSTRACT, CONT'D Exercise: Premise? - assume 3 classes: B and C inherit from A - makes sense to have kinds of A other than B or C Design? - make A instantiable - add default behavior to A - A is no longer abstract - define another child of A, D - A remains abstract - which one is better varies with the situation: which makes it easier to do modifications? INHERITANCE V. INTERFACE What? - OO features to model is-a relationships - inheritance - interface What? - intended use of interface - share common behavior (method headers) among instances of different classes - one class can implement multiple interfaces What? - intended use of inheritance - share common code among the instances of related classes - a single subclass can extend at most one superclass - superclasses include data members and/or methods that are shared by the subclasses - unlike interface, is a specialization relationship ASSIGNMENT 5 DISCUSSION - what are "things" in a game of computer checkers? - what are "actions"? - how do these actions relate to these things? # Under what conditions will the game be over? # How do you check that a human player clicked on a piece? # How do you determine whether a move is invalid? # How do you determine whether a human player may select a piece? # Will a human player be able to deselect a piece if they change their mind? # What happens if the human player selects an invalid move? # How will inheritance be incorporated in your design? # How will you draw the board? - what should we use to model a 2D board of squares? - what do we do to enforce the rules? - classes - need at least 3, up to 5 to do correctly - brainstorm what classes necessary - using inheritance is a requirement! (there is a good way to use it) - rules portion (Checkers) contains - graphical portion (CheckerBoard) - why? - what if wanted to play checkers by displaying to stdout? - could reuse rules portion! - Piece - can I be moved? - needs to know what the rest of the board looks like - how do we have two objects refer to each other? - RegularPiece and King are similar but different... this makes me think of? - inheritance - which of the two strategies discussed above seems most appropriate?