In: Computer Science
I need to make this into a Java Code:
Write a program that prompts the user for a double value representing a radius. You will use the radius to calculate:
You must use π as defined in the java.lang.Math class.
Your prompt to the user to enter the number of days must be:
Enter radius:
Your output must be of the format:
Circle Circumference = circleCircumference
Circle Area = circleArea
Sphere Area = sphereArea
Sphere Volume = sphereVolume
Please make sure to end each line of output with a newline.
Please note that your class should be named CircleSphere.
import java.util.Scanner;
public class CircleSphere {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter radius: ");
double radius = in.nextDouble();
double circleCircumference = 2 * Math.PI * radius;
double circleArea = Math.PI * radius * radius;
double sphereArea = 4 * Math.PI * radius * radius;
double sphereVolume = (4.0 / 3) * Math.PI * radius * radius * radius;
System.out.println("Circle Circumference = " + circleCircumference);
System.out.println("Circle Area = " + circleArea);
System.out.println("Sphere Area = " + sphereArea);
System.out.println("Sphere Volume = " + sphereVolume);
}
}
