Mensuration sums calculator using Java

This source code is written in Java and is about solving mensuration problems by giving the required inputs.

Mensuration sums calculator

This source code is written in Java and is about solving mensuration problems by giving the required inputs. We have imported util package in order to use the scanner class. The program run on the principle of nested switch loops as we have different shapes and different choices, based on the problem you need to solve choose the options given accordingly. On the choice of option, please give the required input in order to find the needed answer. Please use an offline compiler in order to run this program as it may be difficult to work with importing packing in online compilers.

`import java.util.*;public class Geometry{public static void main(String[] args) {Scanner sc = new Scanner(System.in);int choice;System.out.println("MENU:");System.out.println("1.Area");System.out.println("2.Perimeter");System.out.println("3.Volume(For 3D fig)");System.out.println("Enter any of the above option: ");choice = sc.nextInt();switch(choice){case 1: char ch;System.out.println("Area of :");System.out.println( "A. Square");System.out.println( "B. Rectangle");System.out.println( "C. Circle");System.out.println( "D.Triangle");System.out.println( "E.Rhombus");ch=sc.next().charAt(0);switch(ch){case 'A' :System.out.println("Enter side of square: ");double side = sc.nextDouble();double areaS = side * side;System.out.println("Area of square is: " + areaS);sc.close();break;case 'B' :System.out.println("Enter length and breadth of rectangle: ");System.out.println("Enter length of rectangle: ");double length = sc.nextDouble();System.out.println("Enter breadth of rectangle: ");double breadth = sc.nextDouble();double areaRe = length * breadth;System.out.println("Area of ractangle is: " + areaRe);sc.close();break;case 'C' :System.out.println("Enter radius of circle: ");double radius = sc.nextDouble();double areaC = (22 * radius * radius)/7;System.out.println("Area of circle is: " + areaC);sc.close();break;case 'D' :System.out.println("Enter height and base of traingle: ");System.out.println("Enter height of triangle: ");double height = sc.nextDouble();System.out.println("Enter base of triangle ");double base = sc.nextDouble();double areaT = (height * base )/2;System.out.println("Area of triangle is: " + areaT);sc.close();break;case 'E' : System.out.println("Enter length of both the diagonals: ");System.out.println("Enter length of first diagonal: ");double fdiagonal = sc.nextDouble();System.out.println("Enter length of second diagonal: ");double sdiagonal = sc.nextDouble();double areaRh = (fdiagonal * sdiagonal )/2;System.out.println("Area of triangle is: " + areaRh);sc.close();break;default:System.out.println("wrong choice");}break;case 2:char ch1;System.out.println("Perimeter");System.out.println( "A. Square");System.out.println( "B. Rectangle");System.out.println( "C. Circle");System.out.println( "D.Triangle");System.out.println( "E.Rhombus");ch1=sc.next().charAt(0);switch(ch1){case 'A' :System.out.println("Enter side of square: ");double side = sc.nextDouble();double periS = 4 * side;System.out.println("Perimeter of square is: " + periS);sc.close();break;case 'B' :System.out.println("Enter length and breadth of rectangle: ");System.out.println("Enter length of rectangle: ");double length = sc.nextDouble();System.out.println("Enter breadth of rectangle: ");double breadth = sc.nextDouble();double periRe = (length + breadth)*2;System.out.println("Perimeter of rectangle is: " + periRe);sc.close();break;case 'C' :System.out.println("Enter radius of circle: ");double radius = sc.nextDouble();double periC = (2 * 22 * radius)/7;System.out.println("Circumference/Perimeter of circle is: " + periC);sc.close();break;case 'D' :System.out.println("Enter sides of traingle: ");System.out.println("Enter side A of triangle: ");double sideA = sc.nextDouble();System.out.println("Enter side B of triangle ");double sideB = sc.nextDouble();System.out.println("Enter side C of triangle ");double sideC = sc.nextDouble();double periT = sideA+sideB+sideC;System.out.println("Perimeter of triangle is: " + periT);sc.close();break;case 'E' : System.out.println("Enter side of rhombus:");double side1 = sc.nextDouble();double periRh = 4 * side1;System.out.println("Perimeter of rhombus is: " + periRh);sc.close();break;default:System.out.println("wrong choice");}break;case 3:char ch2;System.out.println("Volume of :");System.out.println( "A. Cube");System.out.println( "B. Cuboid");System.out.println( "C. Cone");System.out.println( "D.Cylinder");System.out.println( "E.Sphere");ch2=sc.next().charAt(0);switch(ch2){case 'A' : System.out.println("Enter side of cube:");double side = sc.nextDouble();double volCb = side * side * side;System.out.println("Volume of cube is: " + volCb);sc.close();break;case 'B' : System.out.println("Enter length of cuboid:");double length = sc.nextDouble();System.out.println("Enter breadth of cuboid:");double breadth = sc.nextDouble();System.out.println("Enter height of cuboid:");double height = sc.nextDouble();double volCd = length * breadth * height;System.out.println("Volume of cuboid is: " + volCd);sc.close();break;case 'C' :System.out.println("Enter radius of cone:");double radius = sc.nextDouble();System.out.println("Enter height of cuboid:");double height1 = sc.nextDouble();double volCo = (22 * radius * radius * height1)/21;System.out.println("Volume of cone is: " + volCo);sc.close();break;case 'D' :System.out.println("Enter radius of cylinder:");double radius1 = sc.nextDouble();System.out.println("Enter height of cylinder:");double height2 = sc.nextDouble();double volCy = (22 * radius1 * radius1 * height2)/7;System.out.println("Volume of cylinder is: " + volCy);sc.close();break;case 'E' :System.out.println("Enter radius of sphere:");double side1 = sc.nextDouble();double volS = (4 * 22 * side1 * side1 * side1)/21;System.out.println("Volume of sphere is: " + volS);sc.close();break;default:System.out.println("wrong choice");}break;default:System.out.println("wrong choice");}}}`