Skip to content

Instantly share code, notes, and snippets.

@rr-codes
Last active September 27, 2018 06:04
Show Gist options
  • Save rr-codes/4ca7e4671d32f02bede0b5d36c215933 to your computer and use it in GitHub Desktop.
Save rr-codes/4ca7e4671d32f02bede0b5d36c215933 to your computer and use it in GitHub Desktop.
import java.util.Objects;
/**
* A class that represents a circle. The circle is defined by its two-dimensional center point and its radius.
* The class allows circles to be compared using the radius of each circle. The class ensures that all circle objects will always have a radius greater than zero.
*/
public class Circle {
// ATTRIBUTES
private double x, y, r;
// CONSTRUCTORS
/**
* Initializes this circle with center point located at (0, 0) and radius equal to 1.
*/
public Circle() {
}
/**
* Initializes this circle with center point located at (x, y) and radius equal to r.
*
* @param x the x-coordinate of the center point of the circle
* @param y the y-coordinate of the center point of the circle
* @param r the radius of the circle
* @throws IllegalArgumentException if the radius is not greater than zero
* @pre. r > 0
*/
public Circle(double x, double y, double r) {
}
/**
* Initializes this circle with the same center point and radius as other
*
* @param other the circle to copy
*/
public Circle(Circle other) {
}
// GETTERS AND SETTERS
/**
* Returns the x-coordinate of the center point of the circle
*
* @return the x-coordinate of the center point of the circle
*/
public double getCenterX() {
}
/**
* Returns the y-coordinate of the center point of the circle
*
* @return the y-coordinate of the center point of the circle
*/
public double getCenterY() {
}
/**
* Returns the radius of the circle
*
* @return the radius of the circle
*/
public double getRadius() {
}
/**
* Sets the center point of this circle
*
* @param x the new x-coordinate of the center of this circle
* @param y the new y-coordinate of the center of this circle
*/
public void setCenter(double x, double y) {
}
/**
* Sets the radius of this circle
*
* @param r the new radius of this circle
* @throws IllegalArgumentException if r is not greater than zero
* @pre. r > 0
*/
public void setRadius(double r) {
}
// CUSTOM METHODS
/**
* Returns the area of this circle using A = pi * r ^ 2
*
* @return the area of this circle using A = pi * r ^ 2
*/
public double getArea() {
}
/**
* Moves the circle by the specified coordinates x, y
*
* @param x the amount to shift horizontally
* @param y the amount to shift vertically
*/
public void moveBy(double x, double y) {
}
/**
* Returns true if the point is inside or on this circle. A point is contained in a circle if the Euclidean distance of the absolute difference of the coordinates is less than or equal to the radius of the circle
*
* @param x the x coordinate of the point
* @param y the y coordinate of the point
* @return true if circle contains point; false if the point is outside the circle
*/
public boolean containsPoint(double x, double y) {
}
// OVERRIDDEN METHODS
/**
* Compares two circles by their radius. The result is negative if this circle has a smaller radius than the other circle. The result is positive if this circle has a larger radius than the other circle. The result is 0 if both circles have the same radius.
*
* @param other the circle to be compared
* @return the value 0 if both circles have the same radius; a negative value if this circle has a smaller radius than the other circle; and a positive value if this circle has a larger radius than the other circle
*/
@Override
public int compareTo(Circle other) {
}
/**
* Compares this circle to the specified object. The result is true if and only if the argument is not null and is a Circle object with center point and radius equal to this circle's center point and radius.
*
* @param obj the object to compare against this circle
* @return true if the given object represents a Circle equivalent to this circle; false otherwise
*/
@Override
public boolean equals(Object obj) {
}
/**
* Returns a hash code for this circle. The hash code is computed using Objects.hash
*
* @return a hash code for this circle
*/
@Override
public int hashCode() {
}
/**
* Returns the string containing the center point of the circle followed by a comma and space, followed by the radius.
*
* @return A string representation of the circle with format "(x, y), r"
*/
@Override
public String toString() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment