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 Lucky draw function in java

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "how to realize the lucky draw function of java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Task

Simulate the whole process of registration and login in the lucky draw

2. Main functions:

1. Register

two。 Log in

3. Log out

4. Lottery

5. Exit the system

Home page:

1. Output menu

two。 Select menu number

3. If the number is selected incorrectly, output "your input is wrong!"

Registration:

1. Enter the user name and password, and the system generates a 4-digit random number as the card number.

two。 Register successfully and output user information

Login:

1. Enter the user name and password at the time of registration, the login is successful, and the system indicates that the login is successful.

two。 If the user name and password are entered incorrectly, prompt the user to continue to enter.

Log out and login:

1. If the user is logged in, log out

two。 If the user is not logged in, it shows that you are not logged in

Lucky draw:

1. Enter the membership card number, and the system generates five 4-digit random numbers as lucky numbers

two。 If your membership card number is one of them, you will be a lucky member today; otherwise, you will not be a lucky member.

Exit the system:

If the user wants to end the use of the system, he can exit the system and end the program.

Code implementation: import java.util.Scanner; class User {/ / user String name; String password; int cardid; User (String name,String password) {this.name=name; this.password=password; cardid= (int) (Math.random () * 9000U1000);} String getName () {return name;} String getPassword () {return password;} int getCardid () {return cardid }} public class Lottery {/ / Lottery system public static void main (String [] args) {/ / main method User [] user=new User [10]; number of int total=0;// registrants int jambo0 / whether or not to log out of system int xchang0 / login status, default is not logged in to int Yachi 1 / / current login user elements do {System.out.println ("* Welcome to the Lucky draw system *"); System.out.println ("\ T1, registration"); System.out.println ("\ T2, login"); System.out.println ("\ T3, login") System.out.println ("\ T4, lucky draw"); System.out.println ("\ T5, exit the system"); System.out.print ("\ t Please select:"); int choice; Scanner reader=new Scanner (System.in); choice=reader.nextInt () Switch (choice) {case 1: if (x _ log _ 0) total = getTotal (user, total); else System.out.println ("you are logging in, please log out before registering! \ n "); break; case 2: if (xylene 0) {int I = 0; do {y = toLogin (user, total) If (yawning music 1) {System.out.println ("your input is wrong, please re-enter it! \ n "); I = 1;} else {x = 1; iS0;}} while (I = = 1) } else System.out.println ("you are logging in! \ n "); break; case 3: if (x _ log _ 1) {x _ log _ 0; System.out.println (" logout successful! \ n ");} else System.out.println (" you are not logged in, please log in first! \ n "); break; case 4: if (Xerox 1) {toLottery (user, y);} else System.out.println (" you are not logged in, please log in first! \ n "); break; case 5: juni1; break; default: System.out.println (" your output is incorrect, please re-enter it! " \ n ");}} while (jackpot 1);} private static void toLottery (User [] user, int y) {/ / lucky draw method int jack0; System.out.println (" Today's lucky membership card number is: "); int cardid [] = new int [5]; cardid [0] = (int) (Math.random () * 9000q1000) Cardid [1] = (int) (Math.random () * 9000 million); cardid [2] = (int) (Math.random () * 9000 million); cardid [3] = (int) (Math.random () * 9000 million); cardid [4] = (int) (Math.random () * 9000 million); for

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