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 cn.jbit.dlc1;import java.util.Scanner;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(System.in); do { System.out.println("******Welcome to the Prize Rich System*******"); System.out.println("/t1.Register"); System.out.println("/t2.Login"); System.out.println("/t3.Raffle"); System.out.println("************************************"); System.out.println("Please select menu:"); int choice = input.nextInt(); switch (choice) { case 1: System.out.println("[Awards Money System> Registration]"); System.out.println("Please fill in personal registration information: "); System.out.print("Username: "); userName = input.next(); System.out.print("Password: "); password = input.next(); // Get 4-digit random numbers as cardNumber = (int)(Math.random()*(max-min))+min; System.out.println("/nRegistered successfully, please remember your membership card number"); System.out.println("Username/tPassword/tMember Card Number"); System.out.println(userName + "/t" + password + "/t" + cardNumber); isRegister = true; // Registration is successful, the flag is set to true break; case 2: System.out.println("[Awards Money System> Login]"); if (isRegister) { // Determine whether to register// 3 times input opportunities for (int i = 1; i <= 3; i++) { System.out.print("Please enter username:"); String inputName = input.next(); System.out.print("Please enter your password: "); String inputPassword = input.next(); if (userName.equals(inputName) && password.equals(inputPassword)) { System.out.println("/nWelcome to: " + userName); isLogin = true; // Login is successful, the flag is set to true break; } else if (i < 3) { System.out.println("Username or password is incorrect, and there is also " + (3 - i) + "Times!"); } else { System.out.println("You entered errors in all 3 times!"); } } } else { System.out.println("Please register first, then log in!"); } break; case 3: System.out.println("[Award Monopoly System> Lucky Lottery]"); if (!isLogin) { // Determine whether to log in to System.out.println("Please log in first, then draw!"); System.out.println("Continue? (y/n)"); answer = input.next(); } else { // Generate 5 4-bit random numbers and save them in the array int[] luckynums = new int[5]; for(int i = 0; i < luckynums.length; i++){ luckynums[i] = (int)(Math.random()*(max-min))+min; } System.out.print("Please enter your card number: "); int yourcard = input.nextInt(); int i; System.out.print("/nThe lucky number for today is: "); for (i = 0; i < luckynums.length; i++) { System.out.print(luckynums[i] + " "); } for (i = 0; i < luckynums.length; i++) { if (luckynums[i] == yourcard) { System.out.println("/nCongratulations! You are today's lucky member!"); break; } } if (i == luckynums.length) { System.out.println("/nSorry! You are not today's lucky member!"); } } break; default: System.out.println("[Your input is wrong!]"); break; } System.out.print("Continue? (y/n):"); answer = input.next(); System.out.println(""); } while ("y".equals(answer)); if ("n".equals(answer)) { System.out.println("System Exit, 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.