指导学习:幸运抽奖
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number = 0;
String username = "";
String password = "";
String username2 = "";
String password2 = "";
int card = 0;
//随机四位数生成
int random = (int)(Math.random()*9000+1000);
int random1 = (int)(Math.random()*9000+1000);
int random2 = (int)(Math.random()*9000+1000);
int random3 = (int)(Math.random()*9000+1000);
int random4 = (int)(Math.random()*9000+1000);
int random5 = (int)(Math.random()*9000+1000);
//循环
while(true){
System.out.println("*****欢迎进入奖客富翁系统*****");
System.out.println("\t1.注册");
System.out.println("\t2.登陆");
System.out.println("\t3.抽奖");
System.out.println("************************");
System.out.print("请选择菜单:");
number = input.nextInt();
switch(number){
//选项1
case 1 :
System.out.println("[奖客富翁系统>注册]");
System.out.println("请填写个人注册信息");
System.out.print("用户名:");
username = input.next();
System.out.print("密码:");
password = input.next();
System.out.println("注册成功,请记好您的会员卡号");
System.out.println("用户名\t密码\t会员卡号");
System.out.println(username + "\t" + password + "\t" + random);
break;
//选项2
case 2:
System.out.println("[奖客富翁系统>登录]");
for(int x = 1 ; x <= 3; x++){
System.out.print("请输入用户名:");
username2 = input.next();
System.out.print("请输入密码:");
password2 = input.next();
if(username2.equals(username) && password2.equals(password) ){
System.out.println("欢迎您:"+username);
break;
}else if((3-x)==0){
System.out.println("您已经输入错了3次用户名和密码,系统退出,再见");
}else{
System.out.println("你还有"+(3-x)+"次机会,要珍惜哦!");
}
}
break;
case 3:
System.out.println("[奖客富翁系统>抽奖]");
System.out.println("请输入您的卡号:");
card = input.nextInt();
System.out.println();
System.out.println("本日的幸运数字为:"+random1+" "+ random2+" " + random3+" " + random4+" " + random5);
if(card == random1 || card == random1 || card == random1 || card == random1 || card == random1){
System.out.println("恭喜您,您是本日的幸运会员!");
}else{
System.out.println("抱歉!您不是本日的幸运会员!");
}
break;
default :
System.out.println("您输入有误,请重新输入");
break;
}
System.out.println("继续吗?(y/n)");
String number2 = input.next();
if(number2.equals("n")){
System.out.println("系统退出,谢谢使用!");
break;
}
}
}
//喜欢小编的话就点个关注呗!