Advertisement
fosterbl

Point.java starter

Feb 12th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. //class header for class Point
  2.  
  3. //instance variables - an int for x and an int for y
  4.  
  5. //default constructor to set x and y to 0
  6.  
  7. //specified constructor to initialize specific values for x and y
  8.  
  9. //accessors/getters for x and y
  10.  
  11. //mutators/setters for x and y
  12.  
  13. //toString - returns a String of the format (x, y)
  14.  
  15. /*Add the following method to the Point class:
  16.  
  17. public int quadrant()
  18.  
  19. Returns which quadrant of the x/y plane this Point object falls in. Quadrant 1 contains all points whose x and y values are both positive. Quadrant 2 contains all points with negative x but positive y. Quadrant 3 contains all points with negative x and y values. Quadrant 4 contains all points with positive x but negative y. If the point lies directly on the x and/or y axis, return 0.
  20. */
  21.  
  22. /*Add the following method to the Point class:
  23.  
  24. public void flip()
  25.  
  26. Negates and swaps the x/y coordinates of the Point object. For example, if the object initially represents the point (5, -3), after a call to flip, the object should represent (3, -5). If the object initially represents the point (4, 17), after a call to flip, the object should represent (-17, -4).
  27. */
  28.  
  29. /*Add the following method to your Point class:
  30.  
  31. public boolean isVertical(Point other)
  32.  
  33. Returns true if the given Point lines up vertically with this Point; that is, if their x coordinates are the same.
  34. */
  35.  
  36. /*Add the following method to the Point class:
  37.  
  38. public double slope(Point other)
  39.  
  40. Returns the slope of the line drawn between this Point and the given other Point. Use the formula (y2 - y1) / (x2 - x1) to determine the slope between two points (x1, y1) and (x2, y2). Note that this formula fails for points with identical x-coordinates
  41. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement