APIs for our Object Examples
An API is a list of the public constructor and method headers, so we can drop “public”
API for Point:
Point(int x, int y) create point at (x,y)
int getX() return x-coordinate
int getY() return y-coordinate
double distanceFromOrigin() return distance of point from origin
void setLocation(int x, int y) set new location for point
void translate(int dx, int dy) move point by (dx, dy) to a new location
String toString() return a String describing a point
Quick example of use:
Point p1 = new Point(2,4);
p1.translate(1,1);
API for PhoneEntry (should have descriptions)
PhoneEntry(String name0, String
phoneNo0)
String getName()
String getPhoneNo()
String areaCode()
void changeAreaCode(String newCode)
boolean isValid()
String toString()
Quick example of use:
PhoneEntry pe1 = new PhoneEntry(“Len”, “617-222-3333”);
System.out.println(“area code = “ + pe1.areaCode());
API for Automobile
Automobile(String
make, String model, int year, String vehicleID)
String getMake() car’s make
String getModel() car’s model
int getYear() car’s model year
String getVIN() car’s vehicle ID
Quick example of use:
Automobile car = new Automobile(“Toyota”, “Camry”, 2011, “1GH1234567”);
System.out.println(“car’s year is “+ car.getYear());