Spot.Java

Posted by Didi Setyapramana On 11:49 PM 0 komentar

 *    the area of the intersection of two spots.
 */
public class Spot {
    //instance variables
    public int x, y;
    private double radius;
    private double area;
    //constructor
    public Spot() {
    }

    public Spot(int x, int y, double radius){
        this.x = x;
        this.y = y;
        this.radius = radius;
        this.setArea();
    }
    
    //methods for access to the size instance variable    
    public void setRadius(double newRadius) {
        if (newRadius >= 0.0) {
            radius = newRadius;
            this.setArea();
        }        
    } 
    
    public int getRadius() {
        return radius;
    }
    
    private void setArea(){
        this.area = Math.PI * Math.pow(radius,2.0);
    }
    public double getArea() {
        return area;
    }
        
    public static void main(String[] argv){
        Spot outter = new Spot();
        outter.setRadius(3.0);
        Spot inner = new Spot (0,0,2.0);

        double intersection = outter.getArea()-inner.getArea();
        System.out.println(intersection);
    }
}

Categories:

0 Response for the "Spot.Java"

Post a Comment