Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package solution;
- import java.io.*;
- import java.util.*;
- import java.text.*;
- import java.math.*;
- import java.util.regex.*;
- import java.lang.reflect.*;
- import java.security.Permission;
- public class Solution {
- public static void main(String[] args) {
- DoNotTerminate.forbidExit();
- try {
- Calculate cal = new Calculate();
- int T = cal.get_int_val();
- while (T--> 0) {
- double volume = 0.0;
- int ch = cal.get_int_val();
- if (ch == 1) {
- int a = cal.get_int_val();
- volume = Calculate.do_calc().get_volume(a);
- } else if (ch == 2) {
- int l = cal.get_int_val();
- int b = cal.get_int_val();
- int h = cal.get_int_val();
- volume = Calculate.do_calc().get_volume(l, b, h);
- } else if (ch == 3) {
- double r = cal.get_double_val();
- volume = Calculate.do_calc().get_volume(r);
- } else if (ch == 4) {
- double r = cal.get_double_val();
- double h = cal.get_double_val();
- volume = Calculate.do_calc().get_volume(r, h);
- }
- cal.output.display(volume);
- }
- } catch (NumberFormatException e) {
- System.out.print(e);
- } catch (IOException e) {
- e.printStackTrace();
- } catch (DoNotTerminate.ExitTrappedException e) {
- System.out.println("Unsuccessful Termination!!");
- }
- } //end of main
- } //end of Solution
- /**
- *This class prevents the user form using System.exit(0)
- * from terminating the program abnormally.
- *
- */
- class DoNotTerminate {
- public static class ExitTrappedException extends SecurityException {}
- public static void forbidExit() {
- final SecurityManager securityManager = new SecurityManager() {
- @Override
- public void checkPermission(Permission permission) {
- if (permission.getName().contains("exitVM")) {
- throw new ExitTrappedException();
- }
- }
- };
- System.setSecurityManager(securityManager);
- }
- } //end of Do_Not_Terminate
Advertisement
Add Comment
Please, Sign In to add comment