Snippets

Tom Paulus CS108_HW2

Created by Tom Paulus
/**
 * Homework Assignment #2
 * Assigned on January 30, 2016
 * Objective: Using Classes
 * Specs: http://www-rohan.sdsu.edu/~masc0555/cs108hw2.txt
 *
 * @author Tom Paulus
 *         Created on 1/30/16.
 */

public class Circle {
    double x;  // Circle's X position
    double y;  // Circle's Y position
    double r;  // Circle's Radius in units

    public Circle() {   // Default Constructor
        this.x = 0;
        this.y = 0;
        this.r = 1;
    }

    public Circle(double x, double y, double r) {  // Custom Constructor
        this.x = x;
        this.y = y;
        this.r = r;
    }

    /**
     * Get the area of the Circle
     *
     * @return {@link double} Area of the circle in units.
     */
    public double getArea() {
        return calcAreaForThisRadius(r);
    }

    /**
     * Get the area of a circle with the provided radius
     *
     * @param radius {@link double} Radius of the Circle
     * @return {@link double} Area of the Circle
     */
    public static double calcAreaForThisRadius(double radius) {
        // Area = pi * r^2
        return Math.PI * Math.pow(radius, 2);
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.