/**************************************************************************** ** COPYRIGHT (C): 1997 Cay S. Horstmann. All Rights Reserved. ** PROJECT: Practical OO Development with C++ and Java ** FILE: Point.java ** PURPOSE: shape class ** VERSION 1.0 ** PROGRAMMERS: Cay Horstmann (CSH) ** RELEASE DATE: 3-15-97 (CSH) ** UPDATE HISTORY: ****************************************************************************/ package practicaloo; import java.awt.Graphics; import java.io.PrintStream; public class Point implements Cloneable { public Point(int x, int y) { _x = x; _y = y; } public Object clone() { try { return super.clone(); } catch(CloneNotSupportedException e) { return null; } } public void move(int dx, int dy) { _x += dx; _y += dy; } public void scale(Point center, double scalefactor) { _x = (int)(_x * scalefactor + center._x * (1 - scalefactor)); _y = (int)(_y * scalefactor + center._y * (1 - scalefactor)); } public int get_x() { return _x; } public int get_y() { return _y; } public void plot(Graphics g) { g.fillOval(_x - 2, _y - 2, 5, 5); } public void print(PrintStream p) { p.print(System.out); } public double distance(Point p) { return Math.sqrt(Math.pow(_x - p.get_x(), 2) + Math.pow(_y - p.get_y(), 2)); } public double angle(Point p) { return Math.atan2(p.get_y() - _y, p.get_x() - _x); } private int _x; private int _y; }