In: Computer Science
Write a Circle class that has the following member variables:
The class should have the following member functions:
Write a program that demonstrates the Circle class by asking the user for the radius, creating a Circle class object and then uses the object to test the class.
Sample output:
Enter the circle's radius: 55.5
Radius: 55.5
Area : 9676.88
Diameter: 111
Circumference: 348.716
class Circle { private double Radius; private final double PI = 3.14159; public Circle(double radius) { this.Radius = radius; } public Circle() { Radius = 0.0; } public double getRadius() { return Radius; } public void setRadius(double radius) { this.Radius = radius; } public double getArea() { return PI * Radius * Radius; } public double getDiameter() { return 2 * Radius; } public double getCircumference() { return 2 * PI * Radius; } } class ClassDemo { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter the circle's radius: "); double radius = in.nextDouble(); Circle circle = new Circle(radius); System.out.println("Radius: " + circle.getRadius()); System.out.println("Area: " + circle.getArea()); System.out.println("Diameter: " + circle.getDiameter()); System.out.println("Circumference: " + circle.getCircumference()); } }