Exam Free Response 1 Practice: GeoTools.quadrantLabel 🌶️🌶️
This is practice in the shape of AP Exam Free Response Question 1 (Methods and Control Structures): a partially-written class, write one of its methods. Below is the start of a GeoTools class that will eventually hold a few helper methods for describing points. Write the quadrantLabel method: given a Point2D, return "I", "II", "III", or "IV" for the quadrant it's in (using the usual math convention: I is +x/+y, II is -x/+y, III is -x/-y, IV is +x/-y), "origin" if both coordinates are 0, or "axis" if exactly one coordinate is 0.
Reference: Point2D — the methods you can call
class Point2D
A point on an ordinary (x, y) coordinate plane, with double coordinates. A Point2D never changes once it is made: translate gives you a new one. You do not write this class; make a point with new Point2D(x, y) and call its methods.
Point2D a = new Point2D(0, 0);
Point2D b = new Point2D(3, 4);
a.distanceTo(b) // 5.0
a.equals(b) // false
a.translate(1, 1).toString() // "(1.0, 1.0)"
b.getX() // 3.0
| Method | What it does |
|---|---|
Point2D(double x, double y) | Makes a point.
|
double getX() | The x-coordinate. Returns the x-coordinate |
double getY() | The y-coordinate. Returns the y-coordinate |
double distanceTo(Point2D other) | The straight-line distance from this point to another.
Returns the distance, as a double |
Point2D translate(double dx, double dy) | A NEW point shifted by dx and dy. The point you call it on does not change.
Returns the shifted point |
boolean equals(Object o) | Whether another object is a Point2D with the same x and y.
Returns true if it is a Point2D at the same coordinates; false otherwise |
String toString() | The point as text, "(x, y)". It is called for you by Returns the point as text |