Chapter 9 Object-Oriented Programming: Inheritance 353 65 set (Cpanel web hosting)
Chapter 9 Object-Oriented Programming: Inheritance 353 65 set 66 { 67 if ( value >= 0 ) // validation needed 68 radius = value; 69 } 70 71 } // end property Radius 72 73 // calculate Circle diameter 74 public double Diameter() 75 { 76 return radius * 2; 77 } 78 79 // calculate Circle circumference 80 public double Circumference() 81 { 82 return Math.PI * Diameter(); 83 } 84 85 // calculate Circle area 86 public double Area() 87 { 88 return Math.PI * Math.Pow( radius, 2 ); 89 } 90 91 // return string representation of Circle 92 public override string ToString() 93 { 94 return “Center = [” + x + “, ” + y + “]” + 95 “; Radius = ” + radius; 96 } 97 98 } // end class Circle Fig. 9.6 Fig. 9.6Fig. 9.FiFi6g. 9.6g. 9.6Circleclass contains an x-y coordinate and a radius. (Part 3 of 3.) Class CircleTest (Fig. 9.7) tests class Circle. Line 14 instantiates an object of class Circle, assigning 37as the x-coordinate value, 43as the y-coordinate value and 2.5 as the radius value. Lines 17 19 use properties X, Yand Radiusto retrieve these values, then concatenate the values to stringoutput. Lines 22 24 use Circle s X, Yand Radius properties to change the x-y coordinates and the radius, respectively. Property Radius ensures that member variable radius cannot be assigned a negative value. Line 28 calls Circle s ToStringmethod implicitly to obtain the Circle s string representation, and lines 32 40 call Circle s Diameter, Circumferenceand Areamethods. After writing all the code for class Circle (Fig. 9.6), we note that a major portion of the code in this class is similar, if not identical, to much of the code in class Point. For example, the declaration in Circleof privatevariables xand yand properties Xand Y are identical to those of class Point. In addition, the class Circleconstructors and method ToString are almost identical to those of class Point, except that they also supply radiusinformation. The only other additions to class Circleare privatemember variable radius, property Radiusand methods Diameter, Circumferenceand Area.
We recommend high quality webhost to host and run your jsp application: christian web host services.