← All resources

Write a program to print the Total Surface Area and Volume of a CUBE, CUBOID, CONE or SPHERE. According to user's choice

import java.util.*;
public class Vol_Area_User_Ch
{
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        int ch, s, l, b, h, r;
        double sh;
        System.out.println("Menu for Total Surface Area And Volume->");
        System.out.println("1. Cube.");
        System.out.println("2. Cuboid.");
        System.out.println("3. Cone.");
        System.out.println("4. Sphere.");
        System.out.println("Enter your choice:");
        ch = sc.nextInt();
        switch(ch)
        {
            case 1:
                System.out.println("Enter the edge of the cube:");
                s = sc.nextInt();
                System.out.println("Total Surface Area:"+(6*s*s));
                System.out.println("Volume: "+(s*s*s));
                break;
            case 2:
                System.out.println("Enter the length:");
                l = sc.nextInt();
                System.out.println("Enter the breadth:");
                b = sc.nextInt();
                System.out.println("Enter the height:");
                h = sc.nextInt();
                System.out.println("Total Surface Area:"+2*(l*b+l*h+b*h));
                System.out.println("Volume: "+(l*b*h));
                break;
            case 3:
                System.out.println("Enter the radius of the base of the cone:");
                r = sc.nextInt();
                System.out.println("Enter the height of the cone:");
                h = sc.nextInt();
                sh = Math.sqrt(r*r+h*h);
                System.out.println("Total Surface Area: "+Math.PI*r*(sh+r));
                System.out.println("Volume:"+1.0/3*Math.PI*r*r*h);
                break;
            case 4:
                System.out.println("Enter the radius of the sphere:");
                r = sc.nextInt();
                System.out.println("Total Surface Area: "+4*Math.PI*r*r);
                System.out.println("Volume:"+4.0/3*Math.PI*r*r*r);
                break;
            default:
                System.out.println("Wrong Choice. Enter again.");
        }
    }
}