### Question:
Calculator { public BigDecimal calculate(String formula) { return calculate(formula, null); }  BigDecimal calculate(String formula); BigDecimal calculate(String formula, Object data); BigDecimal calculate(String formula, Object data, int scale);  }### Answer:
@Test public void calculate() { String formula = "2 * 4 + 3"; BigDecimal value = Calculator.calculate(formula); Assert.assertEquals(new BigDecimal(11), value); }
@Test public void calculate1() { String formula = "2 * a + 3 * b - c"; BigDecimal value = Calculator.calculate(formula, MoreObjects.mapOf("a", 3, "b", 4.2, "c", 2.5)); Assert.assertEquals(new BigDecimal(2).multiply(new BigDecimal(3)) .add(new BigDecimal(3).multiply(new BigDecimal("4.2")).subtract(new BigDecimal("2.5"))), value); }
@Test public void calculate2() { String formula = "3 * b / c"; BigDecimal value = Calculator .calculate(formula, MoreObjects.mapOf("b", 4.2, "c", 2.3), 2); Assert.assertEquals(new BigDecimal("3") .multiply(new BigDecimal("4.2").divide(new BigDecimal("2.3"), 5, RoundingMode.HALF_DOWN)) .setScale(2, RoundingMode.HALF_DOWN), value); }