Answer:
import java.util.Scanner;
public class Circle {
private double radius;
//The constructor
public Circle(){
}
//Method to compute and return the area
public double getArea(double radius){
double area = Math.PI *(radius*radius);
return area;
}
//Accesor method (getRadius)
public double getRadius() {
return radius;
}
}
class CircleTest{
//The main method
public static void main(String[] args) {
//Scanner Class to receive user input
Scanner in = new Scanner(System.in);
System.out.println("Enter Radius");
double r = in.nextDouble();
//Make an instance of the class Circle
Circle circle = new Circle();
//Calculating the area
double calArea = circle.getArea(r);
//Printing out the area
System.out.println("The area is: "+calArea);
}
}
Step-by-step explanation:
- This has been solved with Java Programming Language
- Please follow the comments in the codes
- As required, The class Circle is created with one member variable radius
- A getter method is also created
- A method getArea is also created that computes and returns the area of the circle
- In the class CircleTest The scanner class is used to receive a user value for radius
- An instance of Circle class is created
- The method getArea is called with the instance of the class
- The area is printed out