import java.util.Scanner;
public class Bingo
{
public static void main(String[] args)
{
int choose =0;//判断用户选择的菜单项
do
{
try{
System.out.println("*********欢迎进入奖客富翁系统**********");
System.out.println(" 1.注册 ");
System.out.println(" 2.登录 ");
System.out.println(" 3.抽奖 ");
System.out.println("*********************************");
System.out.println("请选择菜单: ");
Scanner input = new Scanner(System.in);
choose = input.nextInt();
if(choose<1 || choose>3)//输入的不是1~3的数字
{
System.out.println("您的输入有误,请输入1~3的数字!");
continue;
}
break;
}catch(Exception ex)//输入的不是数字
{
System.out.println("您的输入有误");
System.out.println("请输入数字!");
continue;
}
}while(true);
Scanner enter = new Scanner(System.in);
String username =null;
String password =null;
boolean isResign=false;
int num =0;
do{
switch(choose)
{
case 1://注册菜单
System.out.println("[奖客富翁系统>注册]");
System.out.println("请填写个人注册信息:");
System.out.print("用户名:");
username = enter.next();
System.out.println(username);
System.out.print("密码:");
password = enter.next();
System.out.println(password);
num = (int)(Math.random()*9000+1000);//随机的4位卡号
System.out.println();
System.out.println();
System.out.println("注册成功,请记住您的会员卡号和密码");
System.out.println("用户名 \t密码 \t会员卡号");
System.out.println("用户名:"+username+"\t"+"密码:"+password+" \t"+"会员卡号:"+num);
isResign= true;
System.out.print("继续吗?(y/n):");
String str1 = enter.next();
if(str1.equals("n") || str1.equals("N"))
{
System.out.println("系统退出,谢谢使用");
System.exit(0);
}
if(str1.equals("y") || str1.equals("Y"))
{
choose =2;
}
else
{
break;
}
case 2://登录菜单
if(isResign==false)
{
System.out.println("请先注册:");
choose=1;
continue;
}
System.out.println("[奖客富翁系统>登录]");
for(int i=0;i<3;i++)
{
System.out.println("请输入用户名:");
String loginname = enter.next();
System.out.println("请输入密码:");
String loginpassword = enter.next();
if(loginname.equals(username) && loginpassword.equals(password))
{
System.out.println();
System.out.println();
System.out.println("欢迎你"+loginname);
break;
}
else{
System.out.println("输入的用户名或者密码有误,请重新输入");
continue;
}
}
System.out.print("是否继续?(y/n)");
String str2 = enter.next();
if(str2.equals("n") || str2.equals("N"))
{
System.out.println("系统退出,谢谢使用");
System.exit(0);
}
if(str2.equals("y") || str2.equals("Y"))
{
choose =3;
}
else
{
break;
}
case 3://抽奖菜单
if(isResign==false)
{
System.out.println("请先注册:");
choose=1;
continue;
}
System.out.println("[奖客富翁系统>抽奖]");
for(int j =0;j<3;j++)
{
System.out.println("请输入卡号:");
int cardnum = enter.nextInt();
if(cardnum!=num)
{
System.out.println("输入的卡号错误,请重新输入!(超过3次系统自动锁定)");
continue;
}
if(cardnum==num)
{
System.out.println();
System.out.println();
int[] luckynum= new int[5];
System.out.println("今天的5个幸运数字是:");
for(int k=0;k<5;k++)
{
luckynum[k] =(int)(Math.random()*9000+1000);//幸运数字
System.out.println(luckynum[k]);
}
for(int temp:luckynum)
{
if(num==temp)
{
System.out.println("恭喜您成为今日的幸运会员");
System.out.println("系统退出,谢谢使用");
System.exit(0);
}
else
{
System.out.println("抱歉您不是今日的幸运会员");
System.out.println("系统退出,谢谢使用");
System.exit(0);
}
}
}
}
}
break;
} while(true);
}
}