posts - 45,comments - 0,views - 4815
复制代码
import java.util.Arrays;
import java.util.Scanner;


public class LuckyDraw {

    //扫描仪
    static Scanner scanner = new Scanner(System.in);
    //注册的账号和密码
    static String regName, regPwd;
    //登录的状态(0、未登录  1、已登录)
    static int loginState;//默认值为0
    //注册的账号
    static int regNumber;

    /**
     * 启动菜单
     */
    public static void startMenu() {
        boolean b = true;
        while (b) {
            System.out.println("****************欢迎使用XXX抽奖系统*******************");
            System.out.println("\t\t1、注册");
            System.out.println("\t\t2、登录");
            System.out.println("\t\t3、抽奖");
            System.out.println("\t\t0、退出");
            System.out.println("请选择:");
            int choose = scanner.nextInt();

            switch (choose) {
                case 1:
                    reg();
                    break;
                case 2:
                    login();
                    break;
                case 3:
                    draw();
                    break;
                case 0:
                    System.out.println("[谢谢使用,系统已退出!]");
                    b = false;
                    break;
                default:
                    System.out.println("[选择错误,请重新选择!]");
                    break;
            }
        }
    }

    /**
     * 用户注册
     */
    public static void reg() {
        System.out.println("抽奖系统>>>用户注册");
        System.out.println("请输入注册的账号和密码:");
        regName = scanner.next();
        regPwd = scanner.next();
        //随机四位数(1000-9999)的卡号
        regNumber = (int) (Math.random() * 9000 + 1000);
        System.out.println("[注册成功,请记住您的会员卡号!]");
        System.out.println("用户名:" + regName + "\t注册密码:" + regPwd + "\t会员卡号:" + regNumber);
    }

    /**
     * 登录
     */
    public static void login() {
        //先判断是否注册
        if (regName == null || regPwd == null) {
            System.out.println("[登录失败,你还未注册!]");
            return;
        }
        System.out.println("抽奖系统>>>用户登录");
        int count = 1;
        while (count <= 3) {
            System.out.println("请输入登录的账号和密码:");
            String loginName = scanner.next();
            String loginPwd = scanner.next();
            //验证
            if (loginName.equals(regName) && loginPwd.equals(regPwd)) {
                System.out.println("[登录成功!]");
                loginState = 1;  //已登录
                break;
            } else {
                System.out.println("[登录失败,账号或密码错误!]");
                count++;
            }
        }
    }

    /**
     * 抽奖
     */
    public static void draw() {
        if (loginState == 0) {
            System.out.println("[抽奖失败,你还未登录!]");
            return;
        }
        System.out.println("抽奖系统>>>幸运抽奖");
        System.out.println("请输入会员卡号:");
        int inputNumber = scanner.nextInt();
        //验证卡号是否输入正确?
        if (inputNumber != regNumber) {
            System.out.println("[抽奖失败,卡号输入错误!]");
            return;
        }
        //生成一组幸运数字
        int[] luckyNumber = new int[100];
        for (int i = 0; i < luckyNumber.length; i++) {
            luckyNumber[i] = (int) (Math.random() * 9000 + 1000);
        }
        System.out.println("今日幸运数字:" + Arrays.toString(luckyNumber));
        //验证是否中奖?
        for (int number : luckyNumber) {
            if (inputNumber == number) {
                System.out.println("[恭喜你,是今日的幸运会员!]");
                return;
            }
        }
        System.out.println("[很遗憾,你不是今日的幸运会员!]");
    }

    /**
     * 程序入口
     *
     * @param args
     */
    public static void main(String[] args) {
        startMenu();
    }
}
复制代码

 

posted on   小贤看世界  阅读(80)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示