The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Java overloading
By Guest on 17th December 2018 06:43:36 AM | Syntax: TEXT | Views: 1



New paste | Download | Show/Hide line no. | Copy text to clipboard
  1. import java.io.*;
  2. import java.lang.Math.*;
  3.  
  4. class Volume
  5. {
  6.  
  7.     double a,b,c,e;            
  8.     void vol(double a)
  9.     {
  10.         System.out.println(Math.pow(a,3));     
  11.     }
  12.  
  13.     void vol(double a,double b)
  14.     {
  15.         System.out.println(a*a*b*Math.PI);     
  16.     }
  17.  
  18.     void vol(double a,double b,double c)
  19.     {
  20.         System.out.println(a*b*c);     
  21.     }
  22.  
  23.     public static void main(String args[])throws IOException
  24.     {
  25.         int h;
  26.         double e,f,g;
  27.         Volume ob1 = new Volume();
  28.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  29.        
  30.        
  31.         while(true)
  32.         {
  33.         System.out.println(" 1. Cube \n 2. Cylinder \n 3. Rectangular Box \n 4. Exit");
  34.         h=Integer.parseInt(br.readLine());
  35.         switch(h)
  36.         {
  37.         case 1:     System.out.println("Enter the side of Cube");
  38.                 e=Double.parseDouble(br.readLine());
  39.                 ob1.vol(e);
  40.                 break;
  41.  
  42.         case 2: System.out.println("Enter the radius and height of Cylinder");
  43.                 e=Double.parseDouble(br.readLine());
  44.                 f=Double.parseDouble(br.readLine());
  45.                 ob1.vol(e,f);
  46.                 break;
  47.        
  48.         case 3: System.out.println("Enter the length, width and height of Rectangular Box");
  49.                 e=Double.parseDouble(br.readLine());
  50.                 f=Double.parseDouble(br.readLine());
  51.                 g=Double.parseDouble(br.readLine());
  52.                 ob1.vol(e,f,g);
  53.                 break;
  54.         case 4: System.exit(0);
  55.         }}
  56.     }  
  57. }



  • Recent Pastes