Points Gone Wild

posted by: Ms. Martin 31 January 2011 No Comment

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.

  1. public Point(int x, int y)

    Creates a point with coordinates (x, y).

  2. public void translate(int x, int y)

    Move the point by (x, y).

  3. public void draw(Graphics g)

    Displays the point as a circle of diameter 3 at (x, y). Label with the coordinates.

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

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

  6. 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.
1 Star2 Stars3 Stars4 Stars5 Stars (9 votes, average: 2.22 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>