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

Java program to implement file input stream class to read binary data from image file.

Java program to find length of given string and convert it in to upper or lower case.

Java program to check marks out of Bound exception.

Java program to read a text file and displays it's contents on screen.

Concatenating and Buffering Files in Java जावा में फ़ाइलों को जोड़ना और बफर करना

Java program to merge two text files in to third file.

Java program to check greatest among three numbers where input numbers are given by user.

Write a Java program to calculate the gross salary of an employee, if basic salary of that employee is greater or equal to 20000 and year's of service is equal or greater than 5 years bonus will be 2000 else1000, TA =10%, DA= 20% and HRA=5% of salary.