thieumao

Calculate

Jan 15th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. package solution;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5. import java.text.*;
  6. import java.math.*;
  7. import java.util.regex.*;
  8. import java.lang.reflect.*;
  9. import java.security.Permission;
  10.  
  11. class Calculate
  12. {
  13.     class Output{
  14.    
  15.         public void display(double volume)
  16.         {
  17.             System.out.printf("%.3f\n",volume);
  18.         }
  19.     }
  20.    
  21.    
  22.     Output output;
  23.     Scanner sc;
  24.     public Calculate() {
  25.         output = new Output();
  26.         sc = new Scanner(System.in);
  27.     }
  28.     public int get_int_val() {
  29.         int a = sc.nextInt();
  30.         if(a<=0){throw new NumberFormatException("All the values must be positive");}
  31.         return a;
  32.     }
  33.     public double get_double_val() {
  34.         double a = sc.nextDouble();
  35.         if(a<=0){throw new NumberFormatException("All the values must be positive");}
  36.         return a;
  37.     }
  38.     public static Get_Vol do_calc() {  
  39.         return new Get_Vol();
  40.     }
  41. }
  42.  
  43. class Get_Vol extends Calculate {
  44.     double get_volume(int val) throws IOException {
  45.         return (val*val*val);
  46.     }
  47.     double get_volume(int val, int val2, int val3) throws IOException {
  48.         return val*val2*val3;
  49.     }
  50.     double get_volume(double val) throws IOException {
  51.         return Math.PI*(val*val*val) * (2.0/3.0);
  52.     }
  53.     double get_volume(double val, double val2)throws IOException {
  54.         return Math.PI*(val*val)*val2;
  55.     }  
  56. }
Add Comment
Please, Sign In to add comment