四则运算 网页版
这次实验是四则运算系列的最后一次实验,实验的要求是:做成安卓APP版或者网页版,我们组做的是网页版,实验内容如下:
完成本次实验所使用的软件:MyEclipse(主要是学习java时课外所学习的知识)和tomcat(作为服务器,上传实验程序)
主要代码:
QusetionAction.java:
public HandleRequest chuti(HandleRequest handleRequest){ //有乘除法 if(handleRequest.getChengchufa()){ //有余数 if(handleRequest.getShifuyushu()){ //有负数 if(handleRequest.getShifufushu()){ //有余有负 return getchengchumeiyuyoufu(handleRequest); }else{ //有余没负 return getchengchuyouyumeifu(handleRequest); } } //没有余数 else{ if(handleRequest.getShifufushu()){ //没有余数 有负数 return getchengchumeiyuyoufu(handleRequest); }else{ return getchengchumeiyumeifu(handleRequest); } } }//没有乘除 else{ if(handleRequest.getShifufushu()){ return getjiajianyoufu(handleRequest); }else{ return getjiajianmeifu(handleRequest); } } }
HandleRequest.java:
public class HandleRequest implements Serializable { private Boolean chengchufa;//是否有乘除法 private Boolean shifuyushu;//是否有余数 private Boolean shifufushu;//是否有负数 private int questnum=10; //题目数量 private int maxnum=10;//整数的取值范围 private int correctresultnum;//正确题目数量 private List<Questions> qusetions;//题目集合
Questions.java:
public class Questions implements Serializable{ private int id;//题目号 private float fistnum;//第一个数字 private String fuhao;//运算符号 private float secondnum;//第二个数字 private float correctresult; //正确结果 private float inputresult;//输入结果 private int inputyushu; //输入余数 private int yushu;//余数
QuestionService.java:
public HandleRequest chuti(HandleRequest handleRequest){ //有乘除法 if(handleRequest.getChengchufa()){ //有余数 if(handleRequest.getShifuyushu()){ //有负数 if(handleRequest.getShifufushu()){ //有余有负 return getchengchumeiyuyoufu(handleRequest); }else{ //有余没负 return getchengchuyouyumeifu(handleRequest); } } //没有余数 else{ if(handleRequest.getShifufushu()){ //没有余数 有负数 return getchengchumeiyuyoufu(handleRequest); }else{ return getchengchumeiyumeifu(handleRequest); } } }//没有乘除 else{ if(handleRequest.getShifufushu()){ return getjiajianyoufu(handleRequest); }else{ return getjiajianmeifu(handleRequest); } } }
chuti.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <script language="javascript" src="${pageContext.request.contextPath}/js/jquery-1.4.2.js"></script> <script language="javascript" src="${pageContext.request.contextPath}/js/test.js"></script> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'chuti.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <style type="text/css"> input[name="correct"]:{ border: none; }, #questnum1:{ visibility: hidden; } </style> </head> <body background="images/bk.jpg"> <div align="center"> 题目数量<input type="text" id="questnum" value="${handlerequest.questnum }" disabled> <p> <s:iterator value="#questions" id="questions"> 第<s:property value="id"/>题:<s:property value="fistnum"/><s:property value="fuhao"/><s:property value="secondnum"/>=<input type="text" name="inputresult" id="${id }inputresult"><input name="correct" value="正确答案" disabled><input type="text" name="correctresult" value="${correctresult }" id="${id}correctresult"/><p> </s:iterator> <input type="button" id="panduan" value="判断"> <input type="button" id="returnindex" value="回到主页"> </div> <div align="center" id="questnum1"> 正确题目数: <input type="text" name="correctnum" id="corrextnum" disabled > </div> </body> </html>
index.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <script language="javascript" src="${pageContext.request.contextPath}/js/jquery-1.4.2.js"></script> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>二柱子测试平台</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script language="javascript" src="js/jquery-1.4.2.js"></script> <script language="javascript" src="js/test.js"></script> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <style type="text/css"> #question{ visibility: hidden; background: gray; } </style> <script type="text/javascript"> </script> </head> <body background="images/bk.jpg"> <div id="welcome" align="center"> <h1>欢迎来到二柱子测试平台</h1> </div> <div id="select" align="center"> <s:form action="questionAction_chuti.action"> <p>乘除法:<input type="checkbox" name="chengchufa" id="chengchufa" value=true></input> </p> <p>是否有余数:<input type="checkbox" name="shifuyushu" id="shifuyushu" value=true></input></p> <p> 是否有负数:<input type="checkbox" name="shifufushu" id="shifufushu" value=true></input></p> <p> 题目数量:<input type="text" name="questnum" id="questnum"></input></p> <p>整数最大值:<input type="text" name="maxnum" id="maxnum"></input></p> <input type="submit" value="提交"> </s:form> </div> </body> </html>
实验截图: