public int calculate(Calculation calculation, int num1, int num2) {
   if (num1 > 10 && num2 < num1) {
     return calculation.calculate(num1, num2);
   } else {
     throw new IllegalArgumentException("Invalid input num1: " + num1 + ", num2: " + num2);
   }
 }
Example #2
0
 @Test
 public void testSqrt() {
   Double x = 81.0;
   String operation = "sqrt";
   Double result = 9.0;
   Calculation object = new Calculation();
   object.calculate(x, operation);
   assertEquals(result, object.getTotal());
 }
Example #3
0
 @Test
 public void testAdd() {
   Double x = 4.0;
   Double y = 2.0;
   String operation = "+";
   Double result = 6.0;
   Calculation object = new Calculation();
   object.calculate(x, y, operation);
   assertEquals(result, object.getTotal());
 }
Example #4
0
 @Test
 public void testCos() {
   Double x = 90.0;
   String operation = "cos";
   Double result = Math.cos(x);
   Calculation object = new Calculation();
   object.setTotal(x);
   object.calculate(operation);
   assertEquals(result, object.getTotal());
 }
Example #5
0
 public static void main(String[] args) {
   Calculation calculation = new Calculation();
   System.out.println("-------------------------------");
   System.out.print(" Enter the argument:");
   Double x = getArgumentFromConsole();
   int i = 0;
   while (true) {
     System.out.print(" Enter the operation:");
     String operation = getOperationFromConsole();
     if (!(operation.equals("+")
         || operation.equals("-")
         || operation.equals("*")
         || operation.equals("/"))) {
       if (i == 0) {
         calculation.setTotal(x);
         calculation.calculate(operation);
         i++;
       } else {
         calculation.calculate(operation);
         i++;
       }
     } else {
       System.out.print(" Enter the argument:");
       Double y = getArgumentFromConsole();
       if (i == 0) {
         calculation.calculate(x, y, operation);
       } else {
         calculation.calculate(y, operation);
       }
       i++;
     }
     System.out.println("-------------------------------");
     System.out.println("Result:" + calculation.getTotal());
     System.out.println();
     System.out.println();
   }
 }