Page 458 - Cs_withBlue_J_C11_Flipbook
P. 458

Circle class is as follows:

                1       import Eleven.Distance;  // package imported
                2       import java.util.*;

                3       class Circle
                4       {

                5           double radius,area;
                6           void areaCircle()

                7           {
                8                Scanner sc=new Scanner(System.in);

                9               System.out.println("Enter co-ordinates of first point");
                10              double px1=sc.nextDouble();

                11              double py1=sc.nextDouble();
                12              System.out.println("Enter co-ordinates of second point");
                13              double px2=sc.nextDouble();

                14              double py2=sc.nextDouble();

                15               // Constructor of class Distance invoked to create object
                16              Distance ob=new Distance(px1,py1,px2,py2);
                17              // method belonging to class Distance in package Eleven invoked

                18              radius=ob.calDistance()/2;
                19              area=3.142*radius*radius;

                20              System.out.println("Radius "+radius+" Area "+area);
                21           }

                22      }

              The output of the preceding program is as follows:
              Enter co-ordinates of first point

              4
              3
              Enter co-ordinates of second point
              7
              8
              Radius 2.9154759474226504 Area 26.707000000000004














                456456  Touchpad Computer Science-XI
   453   454   455   456   457   458   459   460   461   462   463