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:

  1. 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.

  2. 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.)

  3. public double distance(Point other)
    Returns the distance between this Point and the given other Point. Look up the distance formula if you forget!
  4. 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.
1 Star2 Stars3 Stars4 Stars5 Stars (10 votes, average: 2.80 out of 5)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>