thieumao

Solution

Jan 15th, 2017
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 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. public class Solution {
  12.  
  13.  public static void main(String[] args) {
  14.    DoNotTerminate.forbidExit();
  15.    try {
  16.     Calculate cal = new Calculate();
  17.     int T = cal.get_int_val();
  18.     while (T--> 0) {
  19.      double volume = 0.0;
  20.      int ch = cal.get_int_val();
  21.      if (ch == 1) {
  22.       int a = cal.get_int_val();
  23.       volume = Calculate.do_calc().get_volume(a);
  24.      } else if (ch == 2) {
  25.       int l = cal.get_int_val();
  26.       int b = cal.get_int_val();
  27.       int h = cal.get_int_val();
  28.       volume = Calculate.do_calc().get_volume(l, b, h);
  29.  
  30.      } else if (ch == 3) {
  31.       double r = cal.get_double_val();
  32.       volume = Calculate.do_calc().get_volume(r);
  33.  
  34.      } else if (ch == 4) {
  35.       double r = cal.get_double_val();
  36.       double h = cal.get_double_val();
  37.       volume = Calculate.do_calc().get_volume(r, h);
  38.  
  39.      }
  40.      cal.output.display(volume);
  41.     }
  42.  
  43.    } catch (NumberFormatException e) {
  44.     System.out.print(e);
  45.    } catch (IOException e) {
  46.     e.printStackTrace();
  47.    } catch (DoNotTerminate.ExitTrappedException e) {
  48.     System.out.println("Unsuccessful Termination!!");
  49.    }
  50.  
  51.  
  52.   } //end of main
  53. } //end of Solution
  54.  
  55. /**
  56.  *This class prevents the user form using System.exit(0)
  57.  * from terminating the program abnormally.
  58.  *
  59.  */
  60. class DoNotTerminate {
  61.  
  62.  public static class ExitTrappedException extends SecurityException {}
  63.  
  64.  public static void forbidExit() {
  65.   final SecurityManager securityManager = new SecurityManager() {
  66.    @Override
  67.    public void checkPermission(Permission permission) {
  68.     if (permission.getName().contains("exitVM")) {
  69.      throw new ExitTrappedException();
  70.     }
  71.    }
  72.   };
  73.   System.setSecurityManager(securityManager);
  74.  }
  75. } //end of Do_Not_Terminate
Advertisement
Add Comment
Please, Sign In to add comment