CSC152 2004F, Class 10: Points, Revisited Admin: * Please use the following subject for email: CSC152 Homework for DATE: YOURNAME CSC152 Homework for Class 10: Eryn O'Neil CSC152 Homework for 2004.09.13: Michael Billups * When you have questions on homework, put QUESTION in the subject of your email * Sorry about Friday. * Office hours in early afternoon this week. * Sam will try to remember to put homework *in the homework folder* so that you can find it. Overview: * Three word phrases: Any problems? * Polar coordinates * Interfaces: Describing common capabilities * Printing vectors, revisited. /TWP/ * The directory needs to match the package! * You need a toString method! * Method names and variable names should begin with lowercase letters. * The one-word constructor was to repeat the word. * However, you could parse a single string into three words this.firstWord = param.subString(0, param.indexOf(" ")); /Polar Coordinates/ * Should you really set the x coordinate in a vector represented by theta and radius? NO! * Hence, we might argue that you should not set x, y, radius, or theta in a two-dimensional vector. * Mutators may not make sense, depending on the implementation you choose. * If mutators don't make sense, you don't modify, you make new ones. * Side note: The goal really is to separate interface (what you can do) from implementation (how you do it). If you find the "what you can do" relies on implementation, you're failing to separate. /Separating Interface from Implementation/ * Problem: Printing these vectors * Recall that we wrote a printYourself method in the Vector class. public void printYourself(PrintWriter pen) { pen.println("(" + this.getX() + "," + this.getY() + ")"); pen.println("theta: " + this.getAngle()); pen.println("radius: " + this.getDistanceFromOrigin()); } * Why did we write that method? * We wanted to see the information. * We wanted to print similar information again and again, but for different vectors. * Once there's a common method, we can make one change and have it work multiple places. * Will the method look any different in NewTwoDimVector (Polar)? * If we used the same names for the methods, this method should be identical. * Can we, as programmers, avoid copying and pasting the code? * Solution? Maybe: We write the method separately, so that it works with *anything* that provides getX, getY, getAngle, and getDistanceFromOrigin * However, we need a way to specify that our classes provide those methods.