一、項目介紹
題目要求
功能要求: 模擬福利彩票36選7,實現彩票的抽獎與中獎通知功能。
1.允許注冊用戶,用戶信息包括用戶id,用戶名,密碼,賬戶金額,電話號碼等屬性。
2.允許注冊用戶購買彩票:手動選號、隨機選號,並允許設置投注數。
3.抽獎功能:要求屏幕上能夠顯示抽獎的號碼滾動過程,按“停止”按鈕給出抽獎結果。特等獎,7個號碼全中。一等獎,6個號碼全中。抽出號碼后,顯示中獎用戶id,中獎的倍數。
4.彩票抽獎通知功能:抽出號碼后,當用戶登錄系統后,系統提示是否中獎。
5.設計一自動注冊用戶(注冊10萬個)、並自動買彩票為用戶買彩票的程序。然后模擬抽獎。
二、團隊名稱、團隊成員介紹(需要有照片)
團隊成員:
-
林羽晴 網絡1513 學渣一枚
-
郭煒埕 網絡1513 團支書
三、項目git地址
https://git.oschina.net/vicheng/caipiaogoumaichoujiangchengxu.git
四、項目git提交記錄截圖(要體現出每個人的提交記錄、提交說明),老師將點擊進去重點考核。
五、項目功能架構圖與主要功能流程圖
- 思維導圖
六、項目運行截圖
-
登錄賬號密
-
隨機選號或手動選號
-
顯示用戶信息
-
-
滾動抽獎並存入數據庫
- 模擬注冊和查看中獎用戶的功能
七、項目關鍵代碼(不能太多)
User.setPassword(NewPasswordField.getPassword());
User.setMoney(NewMoneyField.getText());
User.setTelnum(NewTelnumField.getText());
if(User.getUsername().length()==0){
JOptionPane.showMessageDialog(null, "請輸入用戶名!");
}else if(Arrays.toString(User.getPassword()).length()==0){
JOptionPane.showMessageDialog(null, "請輸入密碼!");
}else if(User.getMoney().length()==0){
JOptionPane.showMessageDialog(null, "請輸入賬戶金額!");
}else if(User.getTelnum().length()==0){
JOptionPane.showMessageDialog(null, "請輸入電話號碼!");
}else{
JOptionPane.showMessageDialog(null, "新用戶" + NewUserField.getText() + "注冊成功!");
}
String strSql = "insert into userreserve(username,password,money,telnum) values(?,?,?,?)";
PreparedStatement prepare = null;
try {
Class.forName(driverName);
connection = DriverManager.getConnection(url, userName, password);
connection.setAutoCommit(false);
prepare = connection .prepareStatement(strSql);
prepare.setString(1,User.getUsername());
prepare.setString(2, Arrays.toString(User.getPassword()));
prepare.setString(3, User.getMoney());
prepare.setString(4, User.getTelnum());
prepare.addBatch();
prepare.executeBatch();
connection.commit();
}catch (SQLException sqlE) {
sqlE.printStackTrace();
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
ArrayList<Integer> list = new ArrayList<>();
Random random = new Random();
int i = 0, num = 0;
while (i < 7) { //產生不重復的隨機數並存入arraylist中
num = random.nextInt(35) + 1;
if (!list.contains(num)) {
list.add(num);
} else continue;
i++;
}
Num1Field.setText(list.remove(0) + "");
Num2Field.setText(list.remove(0) + "");
Num3Field.setText(list.remove(0) + "");
Num4Field.setText(list.remove(0) + "");
Num5Field.setText(list.remove(0) + "");
Num6Field.setText(list.remove(0) + "");
Num7Field.setText(list.remove(0) + "");
}
public void update() throws SQLException{
String strSql = "insert into userreserve(username,password,times,money,telnum,num1,num2,num3,num4,num5,num6,num7) values(?,?,?,?,?,?,?,?,?,?,?,?)";
Connection con = null;
PreparedStatement prepare = null;
ResultSet rs = null;
ArrayList<Integer> list= new ArrayList<Integer>();
try {
Class.forName(driverName); // 加載MySql的驅動程序
con = DriverManager.getConnection(url, userName, password);
con.setAutoCommit(false);
prepare = con.prepareStatement(strSql);
Statement statement=con.createStatement();
statement.executeUpdate("truncate table userreserve");//每次都要先清空
for (long i = 0; i < usernumber; i++) {
for (int k = 1; k <= 36; k++) {
list.add(k);
}
prepare.setString(1,(i+1)+"aaa");
prepare.setString(2, "[1, 2, 3]");
prepare.setInt(3,new Random().nextInt(10)+1);//設置隨機倍數1-10
prepare.setString(4,"100");
prepare.setString(5,"1300");
for (int j = 0; j < 7; j++) {
int locat=new Random().nextInt(list.size());
prepare.setInt(j+6,list.remove(locat));//將隨機產生的號碼放入數據庫
}
list.clear();
prepare.addBatch();
}
prepare.executeBatch();
con.commit();
} catch...
八、尚待改進或者新的想法
**由於測試自動注冊10萬的數據,所以每次注冊都要先刪除原先的數據庫,則容易導致手動注冊的用戶信息丟失,要將抽獎和自動注冊功能連接起來,注冊用戶時遇到相同賬戶時應如何解決;每個用戶可購買多張彩票 **
九、團隊成員任務分配,團隊成員課程設計博客鏈接(以表格形式呈現),標明組長。
任務分配:
- 郭煒埕
用戶端圖形界面設計,創建User類、實現手動選號、隨機選號、設置倍數及屬性,買彩票消費金額和中獎獎金計算,數據庫信息更新
header 1 | header 2 - 林羽晴
用戶注冊信息的存儲,登錄的匹配,通知中獎的功能,管理員界面設計,要求4和要求5,數據庫創建