The requirements are as follows:
(1defines a circle class that contains a double-type RADIUS attribute that represents the radius of the circle, and a Findarea () method returns the area of the circle. (2Define a class Passobject, define a Method Printareas () in the class, and the method is defined as follows: Public voidPrintareas (Cirlce C,intTimes ) Prints each integer radius value between 1 and time in the Printareas method, along with the corresponding area. For example, the Times is 5, the output radius is 1,2,3,4,5, as well as the corresponding circle area. Call the Printareas () method in the main method, and output the current RADIUS value after the call is complete. Packagestudy03; Public classCircle {Private Doubleradius; Public voidSetradius (Doubleradius) { This. Radius =radius; } Public DoubleGetradius () {returnradius; } Public DoubleFindarea () {return3.14*radius*radius; }} Packagestudy03; Public classPassobject { Public voidPrintArea (Circle C,intTime ) {System.out.println ("Radius\t\tarea"); for(inti = 1; I <= time; i++) {C.setradius (i); System.out.println (C.getradius ()+ "\t\t" +C.findarea ()); } }} Packagestudy03; Public classTestpassobject { Public Static voidMain (string[] args) {Circle C=NewCircle (); Passobject PO=NewPassobject (); Po.printarea (c,5); }}
The output results are as follows:
Radius area
1.0 3.14
2.0 12.56
3.0 28.259999999999998
4.0 50.24
5.0 78.5
Java defines a circle class that contains a double-type RADIUS attribute that represents the radius of the circle, and a Findarea () method returns the area of the circle