//import jdk.nashorn.internal.scripts.JO;

import jdk.nashorn.internal.scripts.JO;

import javax.swing.JOptionPane; import java.util.Scanner;

import static java.lang.Integer.MAX_VALUE; import static java.lang.Integer.hashCode; import static java.lang.Integer.parseInt; /import javax.swing.JFrame; import javax.swing.ImageIcon; import javax.swing.JLabel; import java.awt.; import javax.swing.; import java.awt.event.;*/

public class Calculator1 { static Scanner sc = new Scanner(System.in);

public static void main(String[] args)
{
    int j=0;
    String s, t, a, b;
    double area, circumference, r, l, w, diagnols, volume;
    while (j==0)
    {
        int i;
        a = JOptionPane.showInputDialog(null, " 1. Circle\n" +
                " 2. Square\n" +
                " 3. Rectangle\n" +
                " 4. Cube\n" +
                " 5. Cuboid\n" +
                " 6. Triangle\n" +
                " 7. Trapezium\n" +
                " 8. Sphere\n" +
                " 9. Cone\n" +
                "10. Cylinder\n" +
                "11. Right Pyramid\n" +
                "12. Exit", "Options", JOptionPane.INFORMATION_MESSAGE);

        i = parseInt(a);
        /*System.out.println("Select one option from the line below : \n\n");
        System.out.println("1. Circle\n2. Square\n3. Rectangle\n4. Cube\n5. Cuboid\n6. Triangle");
        System.out.println("7. Trapezium\n8. Sphere\n9. Cone\n10. Cylinder\n 11. Pyramid\n 12. Exit");*/
        //int i;
        //i = sc.nextInt();

        if (i==12)
            break;

        switch (i)
        {
            case 1:
                s = JOptionPane.showInputDialog("Enter the Radius of the Circle: ");
                r = Double.parseDouble(s);
                area = Math.PI * (r * r);
                circumference = Math.PI * (2 * r);
                JOptionPane.showMessageDialog(null, "The Area of the Circle = " + area +
                "\nThe Circumference of the circle = " + circumference, "Solution", JOptionPane.INFORMATION_MESSAGE);
                /*System.out.println("The Area of the circle = " + area);
                System.out.println("The Circumference of the circle = " + circumference);*/
                break;
            case 2:
                s = JOptionPane.showInputDialog("Enter the side of the Square: ");
                r = Double.parseDouble(s);
                area = r * r;
                w = 4*r;
                diagnols = (Math.sqrt(2)) * r;
                JOptionPane.showMessageDialog(null, "The Area of the Square = " + area +
                "\nThe  length of the Diagonals = " + diagnols +
                 "\nPerimeter = " + w, "Solution", JOptionPane.INFORMATION_MESSAGE);
                /*System.out.println("The Area of the square = " + area);
                System.out.println("The length of the diagonals = " + diagnols);*/
                break;
            case 3:
                s = JOptionPane.showInputDialog("Enter the length of the Rectangle: ");
                l = Double.parseDouble(s);
                t = JOptionPane.showInputDialog("Enter the width of the Rectangle: ");
                w = Double.parseDouble(t);
                r = (2*l)  + (2*w);
                area = l * w;
                diagnols = Math.sqrt(Math.pow(l, 2) + Math.pow(w, 2));
                JOptionPane.showMessageDialog(null, "The Area of the Rectangle = " + area +
                "\nThe length of the Diagonals = " + diagnols +
                 "\nPerimeter = " + r, "Solution", JOptionPane.INFORMATION_MESSAGE);
                //JOptionPane.showMessageDialog(null, "The length of the Diagonals = " + diagnols, "Solution", JOptionPane.INFORMATION_MESSAGE);
                /*System.out.println("The Area of the rectangle = " + area);
                System.out.println("The length of the diagonals = " + diagnols);*/
                /*JFrame frame = new JFrame();
                ImageIcon icon = new ImageIcon("C:\\Users\\Samartha\\IdeaProjects\\GrizzHacks\\Images\\rectangle.JPG");
                JLabel label = new JLabel(icon);
                frame.add(label);
                frame.setDefaultCloseOperation
                        (JFrame.EXIT_ON_CLOSE);
                frame.pack();
                frame.setVisible(true);*/
                break;
            case 4:
                s = JOptionPane.showInputDialog("Enter the side of the Cube: ");
                l = Double.parseDouble(s);
                area = 6*(l*l);
                volume = (l*l)*l;
                JOptionPane.showMessageDialog(null, "The Surface Area of the Cube = " + area +
                "\nThe Volume of the Cube = " + volume, "Solution", JOptionPane.INFORMATION_MESSAGE);
                break;
            case 5:
                s =  JOptionPane.showInputDialog("Enter the Length of the Cuboid: ");
                l = Double.parseDouble(s);
                t =  JOptionPane.showInputDialog("Enter the Width of the Cuboid: ");
                w = Double.parseDouble(t);
                b =  JOptionPane.showInputDialog("Enter the Height of the Cuboid: ");
                r = Double.parseDouble(b);
                area = 4*(l*w) + 2*(w*r);
                volume = (l*w)*r;
                JOptionPane.showMessageDialog(null, "The Surface Area of Cuboid = " + area +
                 "\nThe Volume of Cuboid = " + volume, "Solution", JOptionPane.INFORMATION_MESSAGE);
                break;
            case 6:
               /* s =  JOptionPane.showInputDialog("Enter the side of the Triangle: ");
                l = parseInt(s);
                area = (Math.sqrt(3)*Math.pow(l,2))/4;
                JOptionPane.showMessageDialog(null, "The Area of the Equilateral Triangle = " + area,
                "Solution", JOptionPane.INFORMATION_MESSAGE);*/
                triangles();
                break;
            case 7:
                s =  JOptionPane.showInputDialog("Enter the Length of the first parallel line: ");
                l = Double.parseDouble(s);
                t =  JOptionPane.showInputDialog("Enter the Length of the second parallel line: ");
                w = Double.parseDouble(t);
                b =  JOptionPane.showInputDialog("Enter the Height of the trapezium: ");
                r = Double.parseDouble(b);
                area = ((l+w)*r)/2;
                JOptionPane.showMessageDialog(null, "The Area of Trapezium = " + area, "Solution", JOptionPane.INFORMATION_MESSAGE);
                break;
            case 8:
                s = JOptionPane.showInputDialog("Enter the Radius of Sphere: ");
                r = Double.parseDouble(s);
                area = (Math.PI*4)*(r*r);
                volume = ((Math.PI*4)*Math.pow(r,3))/3;
                JOptionPane.showMessageDialog(null, "The Surface Area of Sphere = " + area +
                "\nThe Volume of Sphere = " + volume, "Solution", JOptionPane.INFORMATION_MESSAGE);
                break;
            case 9:
                s = JOptionPane.showInputDialog("Enter the Base Radius of the Cone: ");
                r = Double.parseDouble(s);
                t = JOptionPane.showInputDialog("Enter the Height of the Cone: ");
                w = Double.parseDouble(t);
                area = (Math.PI*r)*(r + Math.sqrt(Math.pow(w,2)+Math.pow(r,2)));
                volume = ((Math.PI)*((r*r)*w)/3);
                JOptionPane.showMessageDialog(null, "The Surface Area of the Cone = " + area +
                "\nThe Volume of the Cone = " + volume, "Solution", JOptionPane.INFORMATION_MESSAGE);
                break;
            case 10:
                s = JOptionPane.showInputDialog("Enter the Base Radius of the Cylinder: ");
                r = Double.parseDouble(s);
                t = JOptionPane.showInputDialog("Enter the Height of the Cylinder: ");
                w = Double.parseDouble(t);
                circumference = (Math.PI)*(2*r);
                area = 2*(Math.PI*(r*r)) + (circumference * w);
                volume = (2*(Math.PI*(r*r)))*w;
                JOptionPane.showMessageDialog(null, "The Surface Area of the Cylinder = " + area +
                "\nThe Volume of the Cylinder = " + volume, "Solution", JOptionPane.INFORMATION_MESSAGE);
                break;
            case 11:
                double a1;
                s =  JOptionPane.showInputDialog("Enter the Length of the Rectangle/Square Right Pyramid: ");
                l = Double.parseDouble(s);
                t =  JOptionPane.showInputDialog("Enter the Width of the Rectangle/Square Right Pyramid: ");
                w = Double.parseDouble(t);
                b =  JOptionPane.showInputDialog("Enter the Height of the Rectangle/Square Right Pyramid: ");
                r = Double.parseDouble(b);
                circumference = w/2;
                a1 = l/2;
                area = (l*w) + (l*(Math.sqrt(Math.pow(r,2) + Math.pow(circumference,2)))) + (w*(Math.sqrt(Math.pow(r,2) + Math.pow(a1,2))));
                volume = ((l*w)*r)/3;
                JOptionPane.showMessageDialog(null, "The Surface Area of the Right Pyramid = " + area +
                "\nThe Volume of the Right Pyramid = " + volume, "Solution", JOptionPane.INFORMATION_MESSAGE);
                break;
            default:
                JOptionPane.showMessageDialog(null, "\n" +
                        " Invalid Input!\n" +
                        " Try Again");
                break;
        }
    }
}

public static void triangles()
{
    String s, t,a,b;
    double l, w, height, area, circum, r;
    int k=1, f;
    while(k==1)
    {
        a = JOptionPane.showInputDialog(null, "1. Equilateral Triangle" +
        "\n2. Isosceles Triangle " +
        "\n3. Right Angle Triangle" +
        "\n4. Scalene Triangle \n5. Return to Main Menu", "Triangle Options", JOptionPane.INFORMATION_MESSAGE);
        f = parseInt(a);
        if (f==5)
            break;

        switch (f)
        {
            case 1:
                s =  JOptionPane.showInputDialog("Enter the Side of the Equilateral Triangle: ");
                l = Double.parseDouble(s);
                area = (Math.sqrt(3)*Math.pow(l,2))/4;
                JOptionPane.showMessageDialog(null, "The Area of the Equilateral Triangle = " + area,
                        "Solution", JOptionPane.INFORMATION_MESSAGE);
                break;
            case 2:
                s =  JOptionPane.showInputDialog("Enter the Equal Sides of the Isosceles Triangle: ");
                l = Double.parseDouble(s);
                t =  JOptionPane.showInputDialog("Enter the non-Equal Side of the Isosceles Triangle: ");
                w = Double.parseDouble(t);
                circum = w/2;
                height = Math.sqrt((Math.pow(circum,2)) - (Math.pow(l,2)));
                area = (w*height)/2;
                JOptionPane.showMessageDialog(null, "The Area of the Isosceles Triangle = " + area,
                        "Solution", JOptionPane.INFORMATION_MESSAGE);
                break;
            case 3:
                s =  JOptionPane.showInputDialog("Enter the Base of the Right Triangle: ");
                l = Double.parseDouble(s);
                t =  JOptionPane.showInputDialog("Enter the Height of the Right Triangle: ");
                w = Double.parseDouble(t);
                circum = Math.sqrt((Math.pow(l,2)) + Math.pow(w,2));
                area = (l*w)/2;
                JOptionPane.showMessageDialog(null, "Hypotenuse = "+ circum +
                "\nArea of the Right Triangle = " + area, "Solution", JOptionPane.INFORMATION_MESSAGE);
                break;
            case 4:
                s =  JOptionPane.showInputDialog("Enter the Length of first Side of the Triangle: ");
                l = Double.parseDouble(s);
                t =  JOptionPane.showInputDialog("Enter the Length of second Side of the Triangle: ");
                w = Double.parseDouble(t);
                b =  JOptionPane.showInputDialog("Enter the Length of third Side of the Triangle: ");
                r = Double.parseDouble(b);
                circum = l + w + r;
                height = circum/2;
                area = Math.sqrt((height * (height - l) * (height - w) * (height - r)));
                JOptionPane.showMessageDialog(null, "The Area of Scalene Triangle = " + area, "Solution", JOptionPane.INFORMATION_MESSAGE);
                break;

            default:
                JOptionPane.showMessageDialog(null, "Invalid Input", "Error", JOptionPane.OK_OPTION);
                break;
        }
    }
}

}

Share this project:

Updates