Points Gone Wild
Write Point and PointMain classes. There’s code on the slides from yesterday but try to build them from memory as much as possible! Make sure you update your PointMain class to test your additions as you go.
public Point(int x, int y)
Creates a point with coordinates (x, y).
public void translate(int x, int y)
Move the point by (x, y).
public void draw(Graphics g)
Displays the point as a circle of diameter 3 at (x, y). Label with the coordinates.
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 (yes, that means you need to change your draw method!). 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!
We’ll do this together but try it if you’re done!
- 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.