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(); } }
标签:抽奖,int,System,static,println,幸运,out From: https://www.cnblogs.com/19981206-zxb/p/16898415.html