Packages

Circle.java

package shapes;

public class Circle {
private float radius;

public Circle() {
this.radius = 0.0f;
}

public Circle(float radius) {
this.radius = radius;
}

public float getArea() {
return (float)Math.PI * this.radius * this.radius;
}

public float getCircumference() {
return 2 * (float)Math.PI * this.radius;
}
}


TestCircle.java

import shapes.Circle;

public class TestCircle {
public static void main(String[] args) {
Circle circle1 = new Circle(5.f);
Circle circle2 = new Circle(12.45f);

System.out.println("Circumference of circle1 = " + circle1.getCircumference());
System.out.println("Area of circle1          = " + circle1.getArea());

System.out.println("Circumference of circle2 = " + circle2.getCircumference());
System.out.println("Area of circle2          = " + circle2.getArea());
}

}

Comments

Popular posts from this blog

Zeller's Congruence

Property Event-Delegation

Method with variable arguments