Example 5.3
//pag 71 http://www.greenteapress.com/thinkapjava/thinkapjava.pdf
 
public class example_5_3    
{
 
    public static double area(double radius) {
        return Math.PI*radius*radius;
    }
 
    public static double distance(double x1, double y1, double x2, double y2) {
        double dx = x1 - x2;
        double dy = y1 - y2;
        double result = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2));
        return result;
    }
 
    public static double fred(double xc, double yc, double xp, double yp) {
        return area(distance(xc, yc, xp, yp));
    }
 
    public static void main(String [] args) {
        double area = fred(1.0, 2.0, 4.0, 6.0);
        System.out.println(area);
    }
}

voltar

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.