• 四则运算


      一、程序设计思想:

      这只是初期的想法:操作选择界面 Welcome.jsp,用户可选择出题的操作元数:二元和三元,及题目的相关数目,在Entry.jsp页面中放置出题页面内容,通过用户在上一页面选择的相关参数,来确定出题页面的内容,如二元三元的数目,根据数目生成相关题的信息,在Show.jsp中展示答题情况,用户答题的正确数量,和错误的题的正确答案。因为这是针对小学二年级的学生体验的答题页面,应该考虑到孩子们的体验舒适感,所以页面应较好玩点,下面程序并非完整开发的程序代码,还有一定的改正时间去完善。现在仅简单实现,计时功能正在改善。显示界面仅导入了二元操作。

    二、源程序代码:

    Welcome.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <script type="text/javascript">
    function getValue(value)
    {alert(value);}
    </script>
    <body background="D:image3.jpg"/> 
         <!-- <embed src="D:dad.mp3" loop="11" autostar="true" hidden="false"/> -->
           <form action="Entry.jsp" method="get.jsp"> 
              <h2 align="center">四则运算</h2>     
          <table align="center" border="1" width="500">
             <td>请选择二元运算的出题数目</td>
              <td><SELECT NAME="operationNumber1" id="number1"  SIZE="1"> 
               <OPTION VALUE="10">系统默认(10道题)</OPTION>
               <OPTION VALUE="0">0</OPTION>
               <OPTION VALUE="20">20</OPTION>
               <OPTION VALUE="40">40</OPTION>
               <OPTION VALUE="50">50</OPTION>
               <OPTION VALUE="60">60</OPTION>
               <OPTION VALUE="70">70</OPTION>
               <OPTION VALUE="80">80</OPTION>
              </SELECT>
           </td>
         <tr>
         <td>请选择三元运算的出题数目</td>
              <td><SELECT NAME="operationNumber2" id="number2"  SIZE="1"> 
               <OPTION VALUE="10">系统默认  (10道题)</OPTION>
                <OPTION VALUE="0">0</OPTION>
                <OPTION VALUE="20">20</OPTION>
               <OPTION VALUE="40">40</OPTION>
               <OPTION VALUE="50">50</OPTION>
               <OPTION VALUE="60">60</OPTION>
               <OPTION VALUE="70">70</OPTION>
               <OPTION VALUE="80">80</OPTION>
              </SELECT>
            </td>
           </tr> 
           <tr>
            <td>请选择学习时间:
            <SELECT NAME="Endtime" id="Endtime"  SIZE="1"> 
               <OPTION VALUE="0">系统默认</OPTION>
               <OPTION VALUE="1">30分钟</OPTION>
               <OPTION VALUE="2">60分钟 </OPTION>
                </SELECT>
           </td>
        </tr> 
           <tr align="center">
                    <td colspan="2">
                       <input type="submit" value="开始答题了" />
                        <input type="reset" value="重置" />
                    </td>
                </tr>
            
        </table>
    </body>
    </html>

    Entry.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@page import=" java.util.*"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
              <form action="Show.jsp" method="get.jsp"> 
                   <body background="D:image3.jpg"/> 
                 <h4 align="center" >欢迎小朋友来到答题界面</h4>
                <table align="center" border="0" width="500">
                 <%
                 int n1=Integer.parseInt((request.getParameter("operationNumber1")));
                 int n2=Integer.parseInt((request.getParameter("operationNumber2")));
                 int time=Integer.parseInt((request.getParameter("Endtime")));
                 
                 Scanner in=new Scanner(System.in);
                if(n1!=0)
                {
                session.setAttribute("length1", n1);
                int number1[]=new int[n1];
                int number2[]=new int[n1];
                int Result[]=new int[n1];
                int temp=0;
                String optr[]=new String[n1];
                 for(int i=0;i<number1.length;i++)
                 {
                     number1[i]=(int)(Math.random()*100+1);
                     number2[i]=(int)(Math.random()*100+1);
                 }
                 for(int i=0;i<n1;i++)
                 {
                     int j=(int)(Math.random()*4+1);
                 if(j==1)
                 {
                     optr[i]="+";
                 }
                 else if(j==2)
                     {
                     optr[i]="-";
                     }
                 else if(j==3)
                 {
                     optr[i]="×";
                 }
                 else
                 {
                     optr[i]="÷";
                 }
                 }
                 for(int i=0;i<number1.length;i++)
                 {
                     if(number1[i]==number2[i])
                     {
                         number1[i]=(int)(Math.random()*100+1);
                            number2[i]=(int)(Math.random()*100+1);
                     }
                     if(number1[i]<number2[i])
                     {
                         temp=number2[i];
                         number2[i]=number1[i];
                         number1[i]=temp;
                     }
                     if(optr[i].contentEquals("+"))
                     {
                         while(number1[i]+number2[i]>100)
                         {
                          number1[i]=(int)(Math.random()*100+1);
                          number2[i]=(int)(Math.random()*100+1);
                         }
                     }
                     if(optr[i].contentEquals("÷"))
                     {
                         while(number1[i]%number2[i]!=0)
                         {
                          number1[i]=(int)(Math.random()*81+1);
                          number2[i]=(int)(Math.random()*9+1);
                         }
                     }
                     if(optr[i].contentEquals("×"))
                     {
                         while(number1[i]*number2[i]>81)
                         {
                          number1[i]=(int)(Math.random()*9+1);
                          number2[i]=(int)(Math.random()*9+1);
                         }
                     }
                     %>
                      <tr  align="center">
                         <td><%=number1[i]%>&nbsp;<%=optr[i]%>&nbsp;<%=number2[i] %>&nbsp;=&nbsp;
                                 <input type="text" name="jie<%=i %>" value=" " />
                     </td>
                     </tr>
                     <%
                    if(optr[i]=="+")
                    {
                        Result[i]=number1[i]+number2[i];
                    }
                    else if(optr[i]=="-")
                    {
                        Result[i]=number1[i]-number2[i];
                    }
                    else if(optr[i]=="×")
                    {
                        Result[i]=number1[i]*number2[i];
                    }
                    else
                    {
                        Result[i]=number1[i]/number2[i];
                    }
                     session.setAttribute("Result"+i,Result[i]+"");
                     session.setAttribute("result"+i,number1[i]+optr[i]+number2[i]+"=");
                 }
                }
                if(n2!=0)
                {
                    session.setAttribute("length2", n2);
                    int number1[]=new int[n2];
                    int number2[]=new int[n2];
                    int number3[]=new int[n2];
                    int temp=0;
                    String optr1[]=new String[n2];
                    String optr2[]=new String[n2];
                     for(int i=0;i<n2;i++)
                     {
                         number1[i]=(int)(Math.random()*100+1);
                         number2[i]=(int)(Math.random()*100+1);
                         number3[i]=(int)(Math.random()*100+1);
                     }
                     for(int i=0;i<n2;i++)
                     {
                         int j=(int)(Math.random()*4+1);
                         int k=(int)(Math.random()*4+1);
                     if(j==1)
                     {
                         optr1[i]="+";
                         if(k==1)
                         {
                         optr2[i]="+";
                         }
                         else if(k==2)
                         {
                            optr2[i]="-";
                         }
                         else if(k==3)
                         {
                             optr2[i]="×";
                         }
                         else 
                         {
                             optr2[i]="÷"; 
                         }
                     }
                     else if(j==2)
                         {
                         optr1[i]="-";
                         if(k==1)
                         {
                         optr2[i]="+";
                         }
                         else if(k==2)
                         {
                            optr2[i]="-";
                         }
                         else if(k==3)
                         {
                             optr2[i]="×";
                         }
                         else 
                         {
                             optr2[i]="÷"; 
                         }
                         }
                     else if(j==3)
                     {
                         optr1[i]="×";
                         if(k==1)
                         {
                         optr2[i]="+";
                         }
                         else if(k==2)
                         {
                            optr2[i]="-";
                         }
                         else if(k==3)
                         {
                             optr2[i]="×";
                         }
                         else 
                         {
                             optr2[i]="÷"; 
                         }
                     }
                     else
                     {
                         optr1[i]="÷";
                         if(k==1)
                         {
                         optr2[i]="+";
                         }
                         else if(k==2)
                         {
                            optr2[i]="-";
                         }
                         else if(k==3)
                         {
                             optr2[i]="×";
                         }
                         else 
                         {
                             optr2[i]="÷"; 
                         }
                     }
                     }
                     for(int i=0;i<n2;i++)
                     {
                        do
                         {
                             number1[i]=(int)(Math.random()*100+1);
                                number2[i]=(int)(Math.random()*100+1);
                                number3[i]=(int)(Math.random()*100+1);
                                
                         }while(number1[i]==number2[i]&&number1[i]==number3[i]&&number2[i]==number3[3]);
                         if(optr1[i].contentEquals("+"))
                         {
                             if(optr2[i].contentEquals("+"))
                             {
                             while(number1[i]+number2[i]+number3[i]>100)
                             {
                                 number1[i]=(int)(Math.random()*100+1);
                                    number2[i]=(int)(Math.random()*100+1);
                                    number3[i]=(int)(Math.random()*100+1);
                             }
                             }    
                             if(optr2[i].contentEquals("-"))
                             {
                                 while(number1[i]+number2[i]>100)
                                 {
                                     number1[i]=(int)(Math.random()*100+1);
                                        number2[i]=(int)(Math.random()*100+1);
                                        number3[i]=(int)(Math.random()*100+1);
                                        int result=number1[i]+number2[i]-number3[i];
                                        while(result>100||result<0)
                                        {
                                           number1[i]=(int)(Math.random()*100+1);
                                           number2[i]=(int)(Math.random()*100+1);
                                           number3[i]=(int)(Math.random()*100+1);
                                        }
                                 }
                             }
                             if(optr2[i].contentEquals("×"))
                             {
                                 while(number2[i]*number3[i]>100)
                                 {
                                     number2[i]=(int)(Math.random()*9+1);
                                        number3[i]=(int)(Math.random()*9+1);
                                        if(number1[i]+number2[i]*number3[i]>100)
                                        {
                                           number1[i]=(int)(Math.random()*100+1);
                                        }
                                 }
                             }
                             if(optr2[i].contentEquals("÷"))
                             {
                                 while(number2[i]%number3[i]!=0)
                                 {
                                     number2[i]=(int)(Math.random()*9+1);
                                        number3[i]=(int)(Math.random()*9+1);
                                        if(number1[i]+number2[i]/number3[i]>100)
                                        {
                                           number1[i]=(int)(Math.random()*100+1);
                                        }
                                 }
                             }
                         }
                         if(optr1[i].contentEquals("-"))
                         {
                             if(optr2[i].contentEquals("+"))
                             {
                             while(number1[i]-number2[i]<0)
                             {
                                 number1[i]=(int)(Math.random()*100+1);
                                    number2[i]=(int)(Math.random()*100+1);
                                    while(number1[i]-number2[i]+number3[i]>100)
                                    {
                                       number3[i]=(int)(Math.random()*100+1);
                                    }  
                             }
                             }    
                             if(optr2[i].contentEquals("-"))
                             {
                                 while(number1[i]-number2[i]<0)
                                 {
                                     number1[i]=(int)(Math.random()*100+1);
                                        number2[i]=(int)(Math.random()*100+1);
                                        while(number1[i]-number2[i]-number3[i]<0)
                                        {
                                           number3[i]=(int)(Math.random()*100+1);
                                        }
                                 }
                             }
                             if(optr2[i].contentEquals("×"))
                             {
                                 while(number2[i]*number3[i]>100)
                                 {
                                     number2[i]=(int)(Math.random()*9+1);
                                        number3[i]=(int)(Math.random()*9+1);
                                        while(number1[i]-number2[i]*number3[i]>100)
                                        {
                                           number1[i]=(int)(Math.random()*100+1);
                                        }
                                 }
                             }
                             if(optr2[i].contentEquals("÷"))
                             {
                                 while(number2[i]%number3[i]!=0)
                                 {
                                     number2[i]=(int)(Math.random()*9+1);
                                        number3[i]=(int)(Math.random()*9+1);
                                        while(number1[i]-number2[i]/number3[i]>100)
                                        {
                                           number1[i]=(int)(Math.random()*100+1);
                                        }
                                 }
                             }
                         }
                         if(optr1[i].contentEquals("×"))
                         {
                             if(optr2[i].contentEquals("+"))
                             {
                             while(number1[i]*number2[i]+number3[i]>100)
                             {
                                 number1[i]=(int)(Math.random()*9+1);
                                    number2[i]=(int)(Math.random()*9+1);
                                    number3[i]=(int)(Math.random()*9+1);
                             }
                             }    
                             if(optr2[i].contentEquals("-"))
                             {
                                 while(number1[i]*number2[i]>100)
                                 {
                                     number1[i]=(int)(Math.random()*9+1);
                                        number2[i]=(int)(Math.random()*9+1);
                                        int result=number1[i]*number2[i]-number3[i];
                                        while(result>100||result<0)
                                        {
                                           number3[i]=(int)(Math.random()*100+1);
                                        }
                                 }
                             }
                             if(optr2[i].contentEquals("×"))
                             {
                                 while(number2[i]*number3[i]*number3[i]>100)
                                 {
                                     number2[i]=(int)(Math.random()*9+1);
                                        number3[i]=(int)(Math.random()*9+1);
                                        number1[i]=(int)(Math.random()*9+1);
                                 }
                             }
                             if(optr2[i].contentEquals("÷"))
                             {
                                 while(number1[i]*number2[i]>100)
                                 {
                                     number2[i]=(int)(Math.random()*9+1);
                                        number3[i]=(int)(Math.random()*9+1);
                                        while((number1[i]*number2[i])%number3[i]!=0)
                                        {
                                           number1[i]=(int)(Math.random()*9+1);
                                        }
                                 }
                             }
                         }
                         if(optr1[i].contentEquals("÷"))
                         {
                             if(optr2[i].contentEquals("+"))
                             {
                             while(number1[i]%number2[i]!=0)
                             {
                                 number1[i]=(int)(Math.random()*81+1);
                                    number2[i]=(int)(Math.random()*9+1);
                                    while(number1[i]/number2[i]+number3[i]>100)
                                    {
                                    number3[i]=(int)(Math.random()*100+1);
                                    }
                             }
                             }    
                             if(optr2[i].contentEquals("-"))
                             {
                                 while(number1[i]%number2[i]!=0)
                                 {
                                     number1[i]=(int)(Math.random()*81+1);
                                        number2[i]=(int)(Math.random()*9+1);
                                        while(number1[i]/number2[i]-number3[i]>100)
                                     {
                                     number3[i]=(int)(Math.random()*100+1);
                                     }
                                 }
                             }
                             if(optr2[i].contentEquals("×"))
                             {
                                 while(number1[i]%number2[i]!=0)
                                 {
                                     number2[i]=(int)(Math.random()*9+1);
                                        number3[i]=(int)(Math.random()*9+1);
                                        while(number1[i]/number2[i]*number3[i]>100)
                                        {
                                           number1[i]=(int)(Math.random()*81+1);
                                        }
                                 }
                             }
                             if(optr2[i].contentEquals("÷"))
                             {
                                 while(number1[i]%number2[i]!=0)
                                 {
                                     number1[i]=(int)(Math.random()*81+1);
                                        number2[i]=(int)(Math.random()*9+1);
                                        while((number1[i]/number2[i])%number3[i]!=0)
                                       { 
                                           number3[i]=(int)(Math.random()*9+1);
                                        }
                                 }
                             }
                         }
                        /*if(number1[i]<number2[i])
                         { 
                             temp=number2[i];
                             number2[i]=number1[i];
                             number1[i]=temp;
                             if(number1[i]<number3[i])
                             {
                                 temp=number3[i];
                                 number3[i]=number1[i];
                                 number1[i]=temp;
                             }
                             if(number1[i]<(number2[i]+number3[i]))
                             {
                             while(number1[i]<(number2[i]+number3[i]))
                             {
                                 number1[i]=(int)(Math.random()*100+1);
                                    number2[i]=(int)(Math.random()*100+1);
                                    number3[i]=(int)(Math.random()*100+1);
                             }
                             }
                         }
                         if(optr1[i].contentEquals("+")&&optr2[i].contentEquals("+"))
                         {
                             while(number1[i]+number2[i]+number3[i]>100)
                             {
                              number1[i]=(int)(Math.random()*100+1);
                              number2[i]=(int)(Math.random()*100+1);
                              number3[i]=(int)(Math.random()*100+1);
                             }
                         }
                         if(optr1[i].contentEquals("÷")&&optr2[i].contentEquals("÷"))
                         {
                             while(((number1[i]%number2[i])!=0))
                             {
                                 
                              number1[i]=(int)(Math.random()*81+1);
                              number2[i]=(int)(Math.random()*81+1);
                              number3[i]=(int)(Math.random()*81+1);
                             }
                         }
                         if(optr1[i].contentEquals("×")&&optr2[i].contentEquals("×"))
                         {
                             while(number1[i]*number2[i]*number3[i]>81)
                             {
                              number1[i]=(int)(Math.random()*9+1);
                              number2[i]=(int)(Math.random()*9+1);
                              number3[i]=(int)(Math.random()*9+1);
                             }
                         }*/
                         %>
                          <tr  align="center">
                             <td><%=number1[i]%>&nbsp;<%=optr1[i]%>&nbsp;<%=number2[i] %><%=optr2[i]%>&nbsp;<%=number3[i] %>&nbsp;=&nbsp;
                                     <input type="text" NAME="jie" value="" />
                                     
                         </td>
                         </tr>
                         <%
                     }
                }
                 %>
                  <tr align="center">
                     <td colspan="1">
                        <input type="submit" value="提交答案" />
                    </td>
                </tr>   
                </table>      
    </body>
    </html>

    Show.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
       <table align="center" border="0" width="500">
        <body background="D:image3.jpg"/> 
        <%
        
        int n1=(int)session.getAttribute("length1");
        int n2=(int)session.getAttribute("length2");
        String result[]=new String[n1];
        String Result[]=new String[n1];
        String result_optr[]=new String[n1];
        String signal[]=new String[n1];
        for(int i=0;i<n1;i++)
        {
              result_optr[i]=request.getParameter("jie"+i);//输入答案
              result[i]=(String)session.getAttribute("result"+i);
              Result[i]=(String)session.getAttribute("Result"+i);//正确答案
            
        } 
        %>
        <%
        for(int i=0;i<n1;i++)
        {
            System.out.println(result_optr[i]);
            System.out.println(Result[i]);
            if(Result[i].equals((result_optr[i]).trim()))
            {
                signal[i]="";
            }
            else
            {
                signal[i]="×";
            }
             %>
             <tr>
            <td> <%=result[i]%><%=result_optr[i]%>&nbsp;<%=signal[i]%>&nbsp;答案:<%=Result[i]%>
            <%
            %>
            </td>
        <%
        }%>
    </body>
    </html>

    三、结果截图:

  • 相关阅读:
    Nosql database
    NoSQL
    nodejs and db
    Nodejs and json
    Nodejs异步
    HTTP-304 NOT Modified
    Origin null is not allowed by Access-Control-Allow-Origin
    nodejs MVC
    solr 亿万级数据查询性能測试
    iOS8 对开发人员来说意味着什么?
  • 原文地址:https://www.cnblogs.com/zhao-teng-ass/p/7994607.html
Copyright © 2020-2023  润新知