幸运抽奖项目
package java_Day10; import java.util.Scanner; public class LuckyNumbers { public static void main(String[] args) { // 判断是否继续 String answer = "y"; // 登录账号 String logincode = ""; // 登录密码 String loginpassword = ""; // 会员卡号 int number = 0; //判断是否注册 boolean isRight=false; //判断是否登录 boolean islogin=false; Scanner input = new Scanner(System.in); do { System.out.println("******欢迎进入奖客富翁管理系统*******"); System.out.println("\t\t1.注册"); System.out.println("\t\t2.登录"); System.out.println("\t\t3.抽奖"); System.out.println("请选择菜单:"); int num = input.nextInt(); switch (num) { case 1: System.out.println(" [奖客富翁管理系统--注册]"); System.out.println("请填写个人注册信息"); System.out.println("用户名:"); logincode = input.next(); System.out.println("密码:"); loginpassword = input.next(); // 随机生成4位会员卡号 number = (int) (Math.random() * (9999 - 1000) + 1000); System.out.println("注册成功,请记好您的会员卡号!"); System.out.println("用户名\t密码\t会员卡号"); System.out.println(logincode + "\t" + loginpassword + "\t" + number); isRight=true; break; case 2: if(isRight==true){ System.out.println(" [奖客富翁管理系统--登录]"); for (int i = 1; i <=3; i++) { System.out.println("请输入用户名:"); String inputcode=input.next(); System.out.println("请输入密码:"); String inputpassowrd=input.next(); if(inputcode.equals(logincode)&&inputpassowrd.equals(loginpassword)){ System.out.println("欢迎您:"+logincode); islogin=true; break; }else if(i<3){ System.out.println("您还有"+(3-i)+"次机会"); continue; }else{ System.out.println("您没有机会了!"); break; } } }else{ System.out.println("您还没有注册,请注册之后再来登录!"); } break; case 3: if(islogin==true){ System.out.println(" [奖客富翁管理系统--登录]"); for (int i = 1; i <=3; i++) { System.out.println("请输入您的卡号:"); int kahao=input.nextInt(); if(number==kahao){ //随机数组 int [] numbers=new int[5]; for (int j = 0; j < numbers.length; j++) { numbers[j]=(int) (Math.random() * (9999 - 1000) + 1000); } System.out.println("本期的幸运数字为:"); for (int j = 0; j < numbers.length; j++) { System.out.print(numbers[j]+"\t"); } //输入的幸运数字跟数组中的每一项比较 for (int j = 0; j < numbers.length; j++) { if(number==numbers[j]){ System.out.print("中奖了!"); break; } //j=4 numbers.length-1 if(j==numbers.length-1){ System.out.println("您不是本期幸运用户!"); } } break; }else if(i<3){ System.out.println("您还有"+(3-i)+"次机会!"); continue; }else{ System.out.println("您没有机会了!"); break; } } }else{ System.out.println("请先登录再来抽奖!"); } break; default: System.out.println("输入错误,请重新输入"); break; } System.out.println("继续吗?(y/n)"); answer = input.next(); } while ("y".equals(answer)); if ("n".equals(answer)) { System.out.println("退出系统!"); } } }
package java_Day10; import java.util.Scanner; public class LuckyNumbers { public static void main(String[] args) { // 判断是否继续 String answer = "y"; // 登录账号 String logincode = ""; // 登录密码 String loginpassword = ""; // 会员卡号 int number = 0; //判断是否注册 boolean isRight=false; //判断是否登录 boolean islogin=false; Scanner input = new Scanner(System.in); do { System.out.println("******欢迎进入奖客富翁管理系统*******"); System.out.println("\t\t1.注册"); System.out.println("\t\t2.登录"); System.out.println("\t\t3.抽奖"); System.out.println("请选择菜单:"); int num = input.nextInt(); switch (num) { case 1: System.out.println(" [奖客富翁管理系统--注册]"); System.out.println("请填写个人注册信息"); System.out.println("用户名:"); logincode = input.next(); System.out.println("密码:"); loginpassword = input.next(); // 随机生成4位会员卡号 number = (int) (Math.random() * (9999 - 1000) + 1000); System.out.println("注册成功,请记好您的会员卡号!"); System.out.println("用户名\t密码\t会员卡号"); System.out.println(logincode + "\t" + loginpassword + "\t" + number); isRight=true; break; case 2: if(isRight==true){ System.out.println(" [奖客富翁管理系统--登录]"); for (int i = 1; i <=3; i++) { System.out.println("请输入用户名:"); String inputcode=input.next(); System.out.println("请输入密码:"); String inputpassowrd=input.next(); if(inputcode.equals(logincode)&&inputpassowrd.equals(loginpassword)){ System.out.println("欢迎您:"+logincode); islogin=true; break; }else if(i<3){ System.out.println("您还有"+(3-i)+"次机会"); continue; }else{ System.out.println("您没有机会了!"); break; } } }else{ System.out.println("您还没有注册,请注册之后再来登录!"); } break; case 3: if(islogin==true){ System.out.println(" [奖客富翁管理系统--登录]"); for (int i = 1; i <=3; i++) { System.out.println("请输入您的卡号:"); int kahao=input.nextInt(); if(number==kahao){ //随机数组 int [] numbers=new int[5]; for (int j = 0; j < numbers.length; j++) { numbers[j]=(int) (Math.random() * (9999 - 1000) + 1000); } System.out.println("本期的幸运数字为:"); for (int j = 0; j < numbers.length; j++) { System.out.print(numbers[j]+"\t"); } //输入的幸运数字跟数组中的每一项比较 for (int j = 0; j < numbers.length; j++) { if(number==numbers[j]){ System.out.print("中奖了!"); break; } //j=4 numbers.length-1 if(j==numbers.length-1){ System.out.println("您不是本期幸运用户!"); } } break; }else if(i<3){ System.out.println("您还有"+(3-i)+"次机会!"); continue; }else{ System.out.println("您没有机会了!"); break; } } }else{ System.out.println("请先登录再来抽奖!"); } break; default: System.out.println("输入错误,请重新输入"); break; } System.out.println("继续吗?(y/n)"); answer = input.next(); } while ("y".equals(answer)); if ("n".equals(answer)) { System.out.println("退出系统!"); } } }