Java program to calculate area and perimeter of circle using interfaces.

interface Shape {
    double calculateArea();
}

interface CircleProperties {
    double calculatePerimeter();
}

class Circle implements Shape, CircleProperties {
    private double radius;

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

    public double calculateArea() {
        return Math.PI * radius * radius;
    }

    public double calculatePerimeter() {
        return 2 * Math.PI * radius;
    }
}

public class CircleCalculator {
    public static void main(String[] args) {
        Circle myCircle = new Circle(5.0);

        System.out.println("Area of the circle: " + myCircle.calculateArea());
        System.out.println("Perimeter of the circle: " + myCircle.calculatePerimeter());
    }
}

Comments

Popular posts from this blog

What is a Web Browser? वेब ब्राउज़र क्या है?

Java's Support System जावा का सहयोगी तंत्र

The Internet and Java इंटरनेट और जावा का सम्बन्ध