This task requires the development of a lucky draw system for a shopping mall. Customers must first register as members of the shopping mall. After the member login is successful, they can participate in the lottery.
register
The user selects the "Register" menu and enters the registration interface. After entering the user name and password, the system prompts that the registration is successful and the membership card number is given.
Log in
After the registration is successful, the user selects the "Login" menu and enters the login interface. Enter the username and password at the time of registration. Login is successful and the system prompts a welcome message. If the user and password are entered incorrectly, the user is prompted to continue typing, and there are up to 3 chances.
lottery
After logging in successfully, the user selects the "Rull draw" menu and enters the lucky draw interface. Enter the membership card number, and the system generates 5 4-digit random numbers as lucky numbers. If the membership card number is one of them, you will become a lucky member today.
source code
package .dlc1; import ; public class LuckyNumber5 { /** * Lucky lottery */ public static void main(String[] args) { String answer = "y"; // Identify whether to continue String userName = ""; // username String password = ""; // password int cardNumber = 0; // card number boolean isRegister = false; // Identify whether to register boolean isLogin = false; // Identify whether to log in int max = 9999; int min = 1000; Scanner input = new Scanner(); do { ("***Welcome to the Awards and Monopoly System****"); ("\t1.Register"); ("\t2.Login"); ("\t3.Raffle"); ("***************************"); ("Please select menu:"); int choice = (); switch (choice) { case 1: ("[Awards Monopoly System > Register]"); ("Please fill in your personal registration information:"); ("username:"); userName = (); ("password:"); password = (); // Get 4-digit random number as card number cardNumber = (int)(()*(max-min))+min; ("\nRegister successfully, please remember your membership card number"); ("Username\tPassword\tMember Card Number"); (userName + "\t" + password + "\t" + cardNumber); isRegister = true; // Registration is successful, the flag is set to true break; case 2: ("[Awards Monopoly System > Login]"); if (isRegister) { // Determine whether to register // 3 chances of input for (int i = 1; i <= 3; i++) { ("Please enter the username:"); String inputName = (); ("Please enter your password:"); String inputPassword = (); if ((inputName) && (inputPassword)) { ("\nWelcome to you:" + userName); isLogin = true; // Login is successful, the flag is set to true break; } else if (i < 3) { ("Username or password is wrong, and there is also" + (3 - i) + "One chance!"); } else { ("You entered an error in all 3 times!"); } } } else { ("Please register first and then log in!"); } break; case 3: ("[Awards Monopoly System > Lucky Draw]"); if (!isLogin) { // Determine whether to log in ("Please log in first, then draw!"); ("Continue? (y/n)"); answer = (); } else { // Generate 5 4-bit random numbers and save them in an array int[] luckynums = new int[5]; for(int i = 0; i < ; i++){ luckynums[i] = (int)(()*(max-min))+min; } ("Please enter your card number:"); int yourcard = (); int i; ("\nThe lucky number for today is:"); for (i = 0; i < ; i++) { (luckynums[i] + " "); } for (i = 0; i < ; i++) { if (luckynums[i] == yourcard) { ("\nCongratulations! You are the lucky member today!"); break; } } if (i == ) { ("\nSorry! You are not the lucky member of today!"); } } break; default: ("[Your input is wrong!]"); break; } ("Continue? (y/n):"); answer = (); (""); } while ("y".equals(answer)); if ("n".equals(answer)) { ("The system exits, thank you for using it!"); } } }
It's just a basic small architecture, and there are many things that can be improved. I hope it will be helpful to you.
If you want to learn more about the implementation of the lottery function, please refer to this topic:Lottery function
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.