Added 27 solutions

This commit is contained in:
rshaghoulian
2017-03-05 00:26:42 -06:00
parent af8c2969a4
commit 3a6797a94a
43 changed files with 2823 additions and 598 deletions
@@ -17,7 +17,7 @@ import java.security.Permission;
class Calculate {
static Scanner scan = new Scanner(System.in);
static Output output = new Output();
public static Calculate do_calc() {
return new Calculate();
}
@@ -64,61 +64,3 @@ class Output {
System.out.format("%.3f%n", value);
}
}
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