java-课程设计-彩票购买抽奖程序

彩票抽奖程序

一、小组分工

小组成员 学号班级 小组分工 个人博客连接
祝月(组长) 网络1914-201921123097 界面的设计、用户信息、订单信息、实现滚动抽奖 https://www.cnblogs.com/22225942w/p/14342809.html
李欣欣 网络1914-202921123093 用户的登陆与注册、彩票抽奖、账户充值、博客完善 https://www.cnblogs.com/hcy420/p/14342550.html

二、项目git地址(及提交记录截图)

https://gitee.com/HGYyu/lottery/commits/master?user=HGYyu

提交截图:

三、流程图

流程图

四、运行结果(可实现)

  1. 登陆界面

  2. 注册界面

  3. Menu界面

  4. 彩票购买界面

  5. 账户充值界面

五、可实现主要代码

  • 登陆

    public static boolean  login(String username, String password) {
    		File file = new File("C:\\Users\\lxx599\\Desktop\\user.txt");
    		int temp = 0;
    		try ( BufferedReader br = new BufferedReader(new FileReader(file));) {
    			String strin;
    			
    			while((strin=br.readLine())!=null) {
    				String[] stri = strin.split("\\s+") ;
    				
    				for (int i = 0; i < stri.length; i++) {
    					User u1 = new User();
    					u1.id=stri[0];
    					u1.username=stri[1];
    					u1.password=stri[2];
    					u1.money=Integer.parseInt(stri[3]);
    					u1.tel=stri[4];
    					if(stri[1].equals(username)&&stri[2].equals(password)) {
    						temp++;
    						u=u1;
    						break;
    					}
    				}	
    			}
    			
    				if (temp >= 1)
    					return true;
    			
    		} catch (NumberFormatException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (FileNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
    		return false;
    
    	}
    
  • 注册

    File file = new File("C:\\Users\\lxx599\\Desktop\\user.txt");
            boolean temp = user.User.repeatUser(jTextField2.getText(),jTextField1.getText());
            if(!temp&&file.exists()) {//还有注意txt文件是否为空
            	
    			try ( BufferedWriter bw = new BufferedWriter(new FileWriter(file,true));) {
    				bw.write(jTextField1.getText());
    				bw.write(" ");
    				bw.write(jTextField2.getText());
    				bw.write(" ");
    				bw.write(jTextField3.getText());
    				bw.write(" ");
    				bw.write(jTextField4.getText());
    				bw.write(" ");
    				bw.write(jTextField5.getText());
    				bw.newLine();
    				bw.flush();
    			} catch (IOException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    			JOptionPane.showMessageDialog(null, "注册成功");
    		}
            else JOptionPane.showMessageDialog(null, "该账户已经存在");
            new Login().setVisible(true);dispose();
        
        } 
    
  • 彩票购买

    		
    		int count=0;//中奖号码个数
    		
    		int[] arr = new int[7];
    		int k = 0;
    		while (k < 7) {
    			arr[k] = (int) (1+Math.random() * 36);
    			for(int j=0;j<k;j++) {
    				if(arr[k]==arr[j]) k--;//随机产生不重复的七个数字
    			}
    			k++;
    		}
    	
    		int j=0;
    		for (int i = 0; i < arr.length; i++) {
    			for (j = 0; j < str.length; j++) {
    				if(arr[i]>Integer.parseInt(str[j])) {
    					j++;
    				}
    				else if(arr[i]<Integer.parseInt(str[j])) {
    					i++;
    				}
    				else count++;
    			}
    			if(j==str.length) break;
    		}
    		
    		int special =0;//判断是否有特殊数字
    		for (int i = 0; i < arr.length; i++) {
    			if(arr[i]==specialNumber) {
    				special=1;
    				break;
    			}
    		}
    	
    
  • 用户信息显示

    jLabel5.setText(User.u.getId());
    
            jLabel6.setText(User.u.getUsername());
    
            jLabel7.setText(String.valueOf(User.u.getMoney()));
    
            jLabel8.setText(User.u.getTel());
    

六、展望

虽然我们团队的彩票抽奖程序并没有很完善,但是总体上实现了用户的登陆、注册、选号购票和账户充值等功能。课程设计是一个将课堂是的理论知识付诸于实践的一个良好机会,有效促进我们进一步学习GUI界面设计、增加查看订单信息的功能、进一步了解和学习数据库。在之后想要采取的使用数据库的方式来读写信息。

posted @ 2021-01-29 03:45  羊腿桂鱼yu  阅读(182)  评论(0编辑  收藏  举报