Adding to the Point Class
posted by: Ms. Martin
11 January 2011
No Comment
Add the following methods to the Point class and update the PointMain class to test your additions:
-
public boolean isVertical(Point other)
Returns true if the given Point lines up vertically with this Point; that is, if their x-coordinates are the same.
-
public void setColor(Color myColor)
Sets the color of this point. You will first need to create a field of type Color. When the point is drawn, it should appear in that color. The pen should then be set back to black (or, to be fancier, to the color it was before drawing the point. How would you save it? Take a look at the Graphics reference.)
- public double distance(Point other)
Returns the distance between this Point and the given other Point. Look up the distance formula if you forget! - Write a separate main to complete the earthquake simulation described on slide 7. Use the file cities.txt. You will need to build an array of points using the number of cities given at the top of the data file. You will prompt the user for epicenters over and over again until the user quits.






