Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the raffle system by Java

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you the relevant knowledge of how to achieve the lottery system in Java. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

Demand Analysis of Lottery system

1) the three main functions of the lottery system are login, registration and lottery.

2) the login requirement means that the user is allowed to enter his account password to log in. The user enters his account number to match the registered user in the system. If the account number does not exist, the password can be entered three times. After the login is successful, the main interface will display the account information of the logged-in user.

3) Registration requirements allow users to enter their account first, and then the system queries whether the user account name already exists. If it already exists, let the user re-enter it, and then enter the next password. The password requirement is a 6-digit string. After successful registration, the system will randomly assign a four-digit id number that is different from the existing account.

4) the prerequisite for the realization of lottery demand function is that users are logged in. When the premise is satisfied, the system randomly selects five different users from the existing users to mark them as lucky users, and then determines whether the online users have been selected.

5) the data is stored in a file system and imported into java.io.* package

6) the login user information is saved in ArrayList, and the lucky user number and id are saved in HasMap with a length of 5, where its id is Key,name and Value.

Matters needing attention

Be sure to create more than five users in user.txt before running the code.

The complete code import java.util.Scanner;import java.util.ArrayList;import java.io.*;import java.util.StringTokenizer;public class Dos {static boolean logined=false; public static void main (String [] args) {User user=new User (); int kryp0; while ((k=Main (user)) > = 1&&k0) {} return (this.userId = userId);} public String getUserPwd () {return userPwd } public int login (User u) {int inputTimes=3; Scanner scanner=new Scanner (System.in); operatorFile getUserMessage=new operatorFile (); System.out.print ("= > Please enter your user name:"); String uName= "; getUserMessage.setUser (uName=scanner.nextLine ()); ArrayList userMess=getUserMessage.getUserMess (0) If (userMess.size () 0) System.out.print ("= > password entered incorrectly!" + (--inputTimes) > 0? "you still have a chance of" + inputTimes+ "!" : "three opportunities have been used up! enter any exit"); System.out.println (inputTimes > 0? "= > login succeeded! you enter the password" + (4-inputTimes) + "times this time!" : "= = > Login failed!") ; setUserName (inputTimes > 0?uName: ""); Dos.logined=inputTimes > 0 true false; return 0;} public void regist () {User u=new User (); Scanner scanner=new Scanner (System.in); System.out.print ("= = > Please enter a new user name:"); String name While (new operatorFile (name=scanner.nextLine ()). GetUserMess (0). Size () > 0) System.out.print ("this user already exists, registration failed! Please re-enter a new user name: "); System.out.print (" = > Please set your (six-digit) login password: "); String regex =" [0-9] {6} ", pwd; while (! (pwd = scanner.nextLine ()) .login (regex)) System.out.print (" = = > password format is incorrect, please reset your (six-digit) login password: ") System.out.println ("generated unique ID for user:" + (u.userName=name) + ":" + (u.userPwd=pwd)); (new operatorFile ()) .writeUserMess (u); System.out.println ("= > registered successfully!") ;} public static HashMap lucklyUsers=new HashMap (); public void getLuckly () {if (! Dos.logined) {System.out.println ("= = > warning: no user login, no lottery!") ; return;} while (lucklyUsers.size ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report