Use a menu driven programming technique to design a program
Use a menu driven programming technique to design a program using do while to calculate the volume of different shapes (minimum 4 shapes) ??
Solution
I have written the code in Java.
//Code starts here
import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.util.*;
 public class MenuOfVolume
 {
    public static void main(String[] args) throws Exception
    {
        java.util.Scanner in = new java.util.Scanner(System.in);
        String reqyn;
        int reqchoice;
       
        do{
            System.out.println(\"Which shape\'s volume you want to calculate(Choose one option):\ 1.Cube\ 2.Cylinder\ 3.Sphere\ 4.Cone\");//printing menu
            reqchoice = in.nextInt();
            double a,r,h;
            switch(reqchoice){
            case 1:{
            System.out.println(\"Enter the length of cube\");
            a = in.nextDouble();
            System.out.println(\"Volume of Cube is:\ \");
            System.out.println(a*a*a);//Calculating and printing value of volume of cube
            break;
            }
            case 2:{
            System.out.println(\"Enter the radius of cylinder\");
            r = in.nextDouble();          
            System.out.println(\"Enter the height of cylinder\");
            h = in.nextDouble();          
            System.out.println(\"Volume of Cylinder is:\ \");
            System.out.println(3.14*r*r*h);//Calculating and printing value of volume of Cylinder
            break;
            }
            case 3:{
            System.out.println(\"Enter the radius of sphere\");
            r = in.nextDouble();          
            System.out.println(\"Volume of Sphere is:\ \");
            System.out.println((4/3)*3.14*r*r*r);//Calculating and printing value of volume of Sphere
            break;
            }
            case 4:{
            System.out.println(\"Enter the radius of cone\");
            r = in.nextDouble();          
            System.out.println(\"Enter the height of cone\");
            h = in.nextDouble();          
            System.out.println(\"Volume of Cone is:\ \");
            System.out.println(3.14*r*r*h/3);//Calculating and printing value of volume of Cone
            break;
            }
            default : System.out.println(\"Wrong choice\");
            }
            System.out.println(\"Enter you request:(Y/N)\");
            reqyn = in.next();
       }while (reqyn.equals(\"Y\"));
       
   
    }
 }


