Computer Science, asked by napierjack008, 6 months ago

Write a class with name Area which has a method to accept the radius of a sphere. Find and calculate its area and volume. Display both the area and volume of the sphere. Area=4πr 2 Volume=4/3 πr 3

Answers

Answered by Oreki
1

import java.util.Scanner;

public class Area {

double radius,

area,

volume;

void accept( ) {

System.out.print("Enter the radius of sphere - ");

radius = new Scanner(System.in).nextDouble( );

}

void calculate( ) {

area = 4 * Math.PI * Math.pow(radius, 2);

volume = (4d / 3d) * Math.PI * Math.pow(radius, 3);

}

void display( ) {

System.out.printf("Area - %f cm²%nVolume - %f cm³", area, volume);

}

public static void main(String[ ] args) {

Area sphere = new Area( );

sphere.accept( );

sphere.calculate( );

sphere.display( );

}

}

Similar questions