Define a class named Circle represents circle defined area of circular circumference and methods, define and modify access (using the constructor) for its member variables. Draw UML class diagram, write a program to test all methods of the class.
(1) shown in FIG UML as shown below:
(2) creation method first creates Circle class, code is shown below:
package package3;
public class Circle {
private double r;
public double getR() {
return r;
public void setR(double r) {
this.r = r;
}
public void setArea() {
System.out.println("面积为"+3.14*r*r);
public void setLength() {
System.out.println("周长为"+2*3.14*r);
(3) create a test output class to call the code as shown below:
package package3;
public class test {
public static void main(String[] args) {
Circle c=new Circle();
c.setR(2);
System.out.println("半径为"+c.getR());
c.setArea();
C.setLength();|
}
}
(4) Run the program and Detection: