package eecs2030.lab1;

/**
 * A simple class for representing points in 2D Cartesian
 * coordinates. Every <code>Point2D</code> instance has an
 * x and y coordinate.
 * 
 * @author EECS2030 Fall 2016
 *
 */
public class Point2 {

    private double x;
    private double y;
    
    /**
     * Create a point with coordinates <code>(0, 0)</code>.
     */
    public Point2() {
        this.set(0.0, 0.0);
    }
    
    /**
     * Create a point with coordinates <code>(newX, newY)</code>.
     * 
     * @param newX the x-coordinate of the point
     * @param newY the y-coordinate of the point
     */
    public Point2(double newX, double newY) {
        this.set(newX, newY);
    }
    
    /**
     * Returns the x-coordinate of this point.
     * 
     * @return the x-coordinate of this point
     */
    public double getX() {
        return this.x;
    }
    
    /**
     * Returns the y-coordinate of this point.
     * 
     * @return the y-coordinate of this point
     */
    public double getY() {
        return this.y;
    }
    
    /**
     * Sets the x-coordinate of this point to <code>newX</code>.
     * 
     * @param newX the new x-coordinate of this point
     */
    public void setX(double newX) {
        this.x = newX;
    }
    
    /**
     * Sets the y-coordinate of this point to <code>newY</code>.
     * 
     * @param newY the new y-coordinate of this point
     */
    public void setY(double newY) {
        this.y = newY;
    }
    
    
    /**
     * Sets the x-coordinate and y-coordinate of this point to
     * <code>newX</code> and <code>newY</code>, respectively.
     * 
     * @param newX the new x-coordinate of this point
     * @param newY the new y-coordinate of this point
     */
    public void set(double newX, double newY) {
        this.x = newX;
        this.y = newY;
    }
    
    /**
     * Returns a string representation of this point. The string
     * representation of this point is the x and y-coordinates
     * of this point, separated by a comma and space, inside a pair
     * of parentheses. 
     * 
     * @return a string representation of this point
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        String s = String.format("(%s, %s)", this.getX(), this.getY());
        return s;
    }
}
