四则运算二

一、记录开发过程中的时间记录日志

PSP2.1 Personal Software Process Stages Time
Planning 计划 48小时
     
Development 开发  
· Analysis · 需求分析 (包括学习新技术)

一个下午+一晚

(32小时)

· Design Spec ·生成设计文档 2小时
·Design Review ·设计复审(和同事审核设计文档) 1小时
·Coding Standard ·代码规范(为目前的开发制定合适的规范) 1小时
·Design .具体设计 2小时
·Coding ·具体编码 8小时
·Code Review ·代码复审 1小时
.Test ·测试(自我测试、修改代码、提交修改) 1小时
Reporting 报告  
·Test Report ·测试报告 1小时
·Size Measurement ·计算工作量 1小时
·Postmortem & Precess Improvement Plan ·事后总结,并提出过程改进计划 1小时
  合计 51小时

二、程序设计思想

按Bean+Servlet+jsp模式(即MVC模式),首先数据库要建三个表,一个储存用户信息,一个储存题目,一个储存成绩。其余是Java文件,实现对整数,真分数以及混合数的运算。最后写jsp文件,实现网页界面显示。

三、源代码

(这里只粘贴部分代码)

package db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class DBConn {
	private static final String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
	private static final String url = "jdbc:sqlserver://localhost:1433; DatabaseName=Arithmetic";
	private static final String user= "sa";
	private static final String password= "yyq838485140///";

	
	private static Statement stmt = null;
	private static Connection coon= null;
	private static PreparedStatement pstmt;
	private static ResultSet rs;
	static{

		try {
			Class.forName(driver);
			coon = DriverManager.getConnection(url, user, password);
			stmt = coon.createStatement();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	static public Connection getConnection(){
		return coon;
	}
	
	
	
	public static void close() {
		if(rs!=null){
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}finally{
				try{
					if(pstmt!=null)
						pstmt.close();
				}catch(SQLException e){
					e.printStackTrace();
				}finally{
					try{
						if(coon!=null)
							coon.close();
					}catch(SQLException e)
					{
						e.printStackTrace();
					}
				}
			}
		}
		
	}
	public static void main(String[] args) {
		try {
			DBConn.getConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

  

 1 package dao;
 2 
 3 import java.sql.Connection;
 4 import java.sql.PreparedStatement;
 5 import java.sql.ResultSet;
 6 import java.sql.SQLException;
 7 
 8 import db.DBConn;
 9 import model.User;
10 
11 public class UserDao1 {
12 
13     public static void main(String[] args) {
14         
15         User u = new User();
16         u.setUsername("asdsfd");
17         u.setPwd("1111");
18         UserDao1 a = new UserDao1();
19         try {
20             a.insert(u);
21         } catch (SQLException e) {
22             // TODO Auto-generated catch block
23             e.printStackTrace();
24         }
25         
26     }
27         public void insert(User u) throws SQLException
28         {
29             Connection conn = null;
30             PreparedStatement pstmt = null;
31             ResultSet rs = null;
32             
33             conn = DBConn.getConnection();
34             //pstmt = conn.prepareStatement("insert into User(username,pwd) values(?,?)");
35             pstmt = conn.prepareStatement("insert into user1(username,pwd) values(?,?)");
36             pstmt.setString(1, u.getUsername());
37             pstmt.setString(2, u.getPwd());
38             pstmt.executeUpdate();
39             
40             DBConn.close();
41         }
42         
43         public User selectByUsername(User u) throws SQLException
44         {
45             Connection conn = null;
46             PreparedStatement pstmt = null;
47             ResultSet rs = null;
48             
49             User n = null;
50             conn = DBConn.getConnection();
51             pstmt = conn.prepareStatement("select * from user1 where username=?");
52             pstmt.setString(1, u.getUsername());
53             
54             rs = pstmt.executeQuery();
55             
56             if(rs.next())
57             {
58                 n = new User();
59                 n.setUsername(rs.getString("username"));
60                 n.setPwd(rs.getString("pwd"));
61                 n.setQnum(rs.getInt("qNum"));
62                 n.setEnum(rs.getInt("eNum"));
63                 n.setRnum(rs.getInt("rNum"));
64                 
65             }
66             
67             DBConn.close();
68             return n;
69         }
70         
71         public void update(User u) throws SQLException
72         {
73             Connection conn = null;
74             PreparedStatement pstmt = null;
75             ResultSet rs = null;
76             
77             conn = DBConn.getConnection();
78             pstmt = conn.prepareStatement("update user1 set qNum=?,eNum=?,rNum=? where username=?");
79             pstmt.setInt(1, u.getQnum());
80             pstmt.setInt(2, u.getEnum());
81             pstmt.setInt(3, u.getRnum());
82             pstmt.setString(4, u.getUsername());
83             pstmt.executeUpdate();
84             
85             DBConn.close();
86         }
87         
88         
89 }
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录</title>



<script type="text/javascript">


</script>



<style type="text/css">
    #input {
            position:absolute;left:0px; top:30%; width:100%;
            }
    #logo  {
    position: absolute;
    left: 0px;
    top: 17px;
    width: 100%;
    z-index: 100;
        }
    img {z-index: -1;}
    #logo form h1 {
    font-style: italic;
    font-size: 46px;
    color: white;
}
</style>

</head>
<body>
<img src="images/p2.jpg" width="100%" height="100%"/>  

    <div id="loginMessage">
        
    </div>
    <div id="logo">
    <form>
    <center>
    <h1>KNY熊出没答题网</h1>
    </center>
    </form>
    </div>
        
    <div id="input">
    <center>
        <form action="Loginac" method="post" onsubmit="return check()">
            <table>
                <tr><td>用户名:</td><td><input type="text" id="n1" name="username"></td><td><span id="userInfo"></span></td></tr>
                <tr><td>密码:</td><td><input type="password" id="pwd" name="pwd"></td><td><span id="pwdInfo"></span></td></tr>
                <tr><td><a href="Logon.html"><input type="button" id="bt1" value="注册"></a></td><td><input type="submit" value="登录"></td></tr>
                <tr><td></td><td><span id="loginResult"></span></td></tr>
            </table>
        </form>
    </center>
    </div>
</body>
</html>
  1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2     pageEncoding="UTF-8"%>
  3  
  4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5 <html>
  6 <head>
  7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8 <title>主页</title>
  9 
 10 <script src="js/jquery-2.1.1.min.js"></script>
 11 
 12 
 13 <script type="text/javascript" src="js/index.js"></script>
 14 
 15 <style type="text/css">
 16     #logo  {
 17     position: absolute;
 18     left: 0px;
 19     top: 17px;
 20     width: 100%;
 21     z-index: 100;
 22         }
 23     img {z-index: -1;}
 24     #logo form h1 {
 25     font-style: italic;
 26     font-size: 36px;
 27     color: #66FFCC;}
 28     #user{position:absolute;left:5%;top:10px;z-index:200;}
 29     #login{position:absolute;left:91%;top:10px;z-index:200;}
 30     #logout{position:absolute;left:95%;top:10px;z-index:200;}
 31      #wrap {position:absolute;left:0px;top:0px;width:100%;height:100%}
 32     #menu {display: none;text-align: center;}
 33     #userInfo {display: none;text-align: center;}
 34     #zuoTiInput {display: none;}
 35     #selectInput {display: none;text-align: center;}
 36     #show {display: none; height: 350px;overflow: auto;}
 37     #right {position:absolute;left:50%;top:40px;height:80%;width:40%}
 38     #left {
 39     position: absolute;
 40     width: 518px;
 41     top: 116px;
 42     left: 48px;
 43     height: 13px;
 44 }
 45     #zuoTiFuZhu {text-align: center;}
 46     #result {text-align: center;}
 47 #user {
 48     color: #000033;
 49 }
 50 #user {
 51     font-weight: bold;
 52 }
 53 #user {
 54     color: #900;
 55 }
 56 #user {
 57     color: #CC0033;
 58 }
 59 </style>
 60 
 61 
 62 </head>
 63 <body>
 64     <img src="images/p4.jpeg" width="100%" height="100%">
 65     <div id="logo">
 66     <form>
 67     <center>
 68     <h1>KNY熊出没答题网</h1>
 69     </center>
 70     </form>
 71     </div>
 72     <!--
 73     <div id="loginBT" align="right">
 74             <a href="Login.html"><button>登录</button></a>
 75     </div>
 76     !-->
 77 <div id="login">
 78     <a href="Login.html"><button>登录</button></a>
 79     </div>
 80 <div id="add">
 81     <a href="Logon.jsp"><button>注册</button></a>
 82     </div>
 83 <div id="user">
 84     您好!${user.username}
 85     </div>
 86     <div id="wrap">
 87     
 88     <div id="left">
 89     
 90     
 91         <div id="loginMessage"></div>
 92 
 93         
 94         <!--<div id="userInfo">
 95             用户名:${user.username}
 96            <!--  <div id="loginBT" align="right">
 97             <a href="Logoutac"><button id="logout">注销</button></a>
 98     </div> !-->
 99         
100 
101       <div id="menu">
102             <button id="zuoTi">做题</button>
103             <button id="selectLiShiShiTi">查询历史试题</button>
104         </div>
105         
106         <div id="zuoTiInput" >
107 
108             <table align="center">
109                 <tr><td>试题类型:</td><td><label>整数式<input type="radio" name="type" value="0" checked="checked"></label></td><td><label>真分数式<input type="radio" name="type" value="1"></label></td></tr>
110                 <tr><td>有无乘除:</td><td><label><input type="radio" name="hasChengChu" value="0" checked="checked"></label></td><td><label><input type="radio" name="hasChengChu" value="1"></label></td></tr>
111                 <tr><td>有无括号:</td><td><label><input type="radio" name="hasKuoHao" value="0" checked="checked"></label></td><td><label><input type="radio" name="hasKuoHao" value="1"></label></td></tr>
112                 <tr><td>最大值:</td><td colspan="2"><input type="text" name="maxNum" value="10"><span id="maxNumInfo"></span></td></tr>
113                 <tr><td>试题个数:</td><td colspan="2"><input type="text" name="num" value="10"><span id="numInfo"></span></td></tr>
114                 <tr><td colspan="3"><input type="button" id="zuoTiInputTiJiao" value="提交"></td></tr>
115             </table>
116 
117         </div>
118 
119         <div id="selectInput">
120             <select id="shiJuanList">
121                 
122             </select>
123             
124             <select id="typeSelect">
125                 <option value="all" selected="selected">
126                     全部
127                 </option>
128 
129                 <option value="right">
130                     正确
131                 </option>
132                 
133                 <option value="wrong">
134                     错误
135                 </option>
136                 
137             </select>
138 
139             <button id="selectShiJuan">
140                 查询
141             </button>
142     </div>
143     
144     
145     <div id="show">
146         <table id="showShiTiTable" align="center" border="1">
147 
148         </table>
149         <div id="zuoTiFuZhu"><button id="jiaoJuanBT">交卷</button><span id="shengYuTime"></span></div>
150         <div id="result">
151             
152         </div>
153     </div>
154         
155     </div>
156 </div>
157 </body>
158 </html

 四、程序运行结果

(部分截图)

 

posted @ 2017-12-06 18:22  DaisyYuan  阅读(143)  评论(0编辑  收藏  举报