CSC152 2005F, Class 19: Java Interfaces Admin: * Donuts! * Reading for tomorrow: Polymorphism * Not quite ready, but soon * Questions on the exam? * polar * getTotal() Overview: * Summary of reading * Questions and answers * Lab /Exam Questions/ Q: How do I create a Vec2D using Polar coordinates? Vec2D p = Vec2D.polar(radius,theta); Q: When testing, do I need to write testers that interact with the user, or can I hard-code the tests and change as necessary? A: Do what you want (unless I've told you something explicit). Q: Shouldn't getTotal() return a double? A: No. double are inaccurate. It makes sense to return the number of cents. Q: What do you want back? A: The number of cents as a long. this.quarters*25 + this.dimes*10 + this.nickels*5 + this.pennies; Side note: Some of you have learned the following EVIL shorthand import java.io.*; Meaning "for an class in the package java.io, if I use the name of the class, assume I mean java.io.NameOfClass" Problem: Leads to ambiguity for the *reader* of your code import java.io.*; import java.util.*; import rebelsky.cs152.*; ... FizzBuzter fb = new FizzBuzter(); Interfaces * Good programming strategy: Separate what from how * Client programmers should only know the what * Helps the person doing the development b/c it can reveal the next step * Helps Sam when he's helping you - Distinguishes between goals of code from what someone happened to write * Supported through interfaces - lists of related methods that we expect certain classes to provide public interface INAME { METHOD DECLARATIONS W/O BODIES } * We tie the how to the what when imlpementing a class public class CNAME implements INAME { } /REFLECTION/ * Another reason to separate the what from the how: Choose different implementations * New form of lab? * Bug/Feature in computing distance (doesn't "wrap around") * Make a new copy of DateHelper.java if you want * Note: if CNAME implements INAME, you can use an object of type CNAME wherever you expect a value of type INAME