答案:希望以下对你有帮助,满意的话记得给分,呵呵:
<%@ page import="java.math.BigDecimal"%>
<html>
<head>
<title>ST8016 Assignment Q5</title>
<script type="text/javascript">
function verify() {
regExp = /\d+\b/;
if (!(regExp.test(thisForm.cashamount.value))) {
alert("You must enter valid amount!");
return false;}
return true;
}
</script>
</head>
<body>
<h1>Assignment 1 - Question 5</h1>
<b>Tax Calculation</b>
<br /><br />
<table border="1" cellpadding="3">
<tr bgcolor="#EEEEEE"><td align="center">Amount</td><td align="center">Tax Rate %</td></tr>
<tr><td align="center">1 - 10,000 </td><td align="center">2.05 % (0.0205)</td></tr>
<tr><td align="center">10,001 - 30,000 </td><td align="center">2.15 % (0.0215)</td></tr>
<tr><td align="center">> 30,000 </td><td align="center">2.50 % (0.0250)</td></tr>
</table>
<form name="thisForm" action="" method=”post”
onsubmit="return verify();">
Amount: <input name=cashamount size=10/> <br/><br/>
<input type=submit value="Calculate Tax Amount"/>
</form>
<table>
<tr>
<td>
<%
String amountStr;
int amount;
double TaxRate,result;
amountStr=request.getParameter("cashamount");
if (amountStr==null)
amount=0;
else
amount=Integer.parseInt(amountStr);
if (amount>=1 && amount<=10000)
TaxRate=0.0205;
else if(amount>=10001 && amount<=30000)
TaxRate=0.0215;
else if(amount>=30000)
TaxRate=0.0250;
else
TaxRate=0;
result=new BigDecimal(amount*TaxRate).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
out.println("Tax Amount: <B>"+result+"</B>");
%>
</td>
</tr>
</table>
</body>
</html>
上一个:delphi当单机按钮是自动生成一个配置文件用来保存edit中的值,下次进入程序就自动读取配置文件
下一个:一个简单的JSP网页程序,运行了以后说有错误,是什么原因??