jsp 和 javaBean 实现计算器功能
try {
calculator.calculate();
} catch (Exception e) {
out.write(e.getMessage());
}
%>
简单的计算器 | |
第一个参数 | |
运算符 | + - * / |
第二个参数 | |
结果 | = |
package de.bvb.domain;
import java.math.BigDecimal;
public class Calculator {
private String firstNum = "0";
private char operator = '+';
private String secondNum = "0";
private String result;
public void calculate() {
BigDecimal first = new BigDecimal(firstNum);
BigDecimal seconde = new BigDecimal(secondNum);
switch (operator) {