import java.util.Scanner;
//随机生成数字抽奖
public class RandomTest {
public static void main(String[] args) {
String answer = ""; // 是否继续
String name = ""; // 用户名
String pw = ""; // 密码
int cardNumber=0 ; // 卡号
boolean zhuce = false; // 是否注册
boolean denglu = false; // 是否登录
int max = 9999;
int min = 1000;
Scanner input = new Scanner(System.in);
do {
System.out.println("*****欢迎进入奖客富翁系统*****");
System.out.println("\t1.注册");
System.out.println("\t2.登录");
System.out.println("\t3.抽奖");
System.out.println("***************************");
System.out.print("请选择菜单:");
int choice = input.nextInt();
switch (choice) {
case 1:
System.out.println("[奖客富翁系统 > 注册]");
System.out.println("请填写个人注册信息:");
System.out.print("用户名:");
name = input.next();
System.out.print("密码:");
pw= input.next();
// 获取4位随机数作为卡号
cardNumber = (int)(Math.random()*(max-min))+min;
System.out.println("\n注册成功,请记好您的会员卡号");
System.out.println("用户名\t密码\t会员卡号");
System.out.println(name + "\t" + pw + "\t" + cardNumber);
zhuce = true; // 注册成功
break;
case 2:
System.out.println("[奖客富翁系统 > 登录]");
if (zhuce) { // 判断是否注册
// 3次输入机会
for (int i = 1; i <= 3; i++) {
System.out.print("请输入用户名:");
String inputName = input.next();
System.out.print("请输入密码:");
String inputPassword = input.next();
if (name.equals(inputName) && pw.equals(inputPassword)) {
System.out.println("\n欢迎您:" + name);
denglu = true; // 登录成功
break;
} else if (i < 3) {
System.out.println("用户名或密码错误,还有" + (3 - 1) + "次机会!");
} else {
System.out.println("您3次均输入错误!");
}
}
} else {
System.out.println("请先注册,再登录!");
}
break;
case 3:
System.out.println("[奖客富翁系统 > 抽奖]");
if (!denglu) { // 判断是否登录
System.out.println("请先登录,再抽奖!");
} else {
//生成5个4位随机数字,保存在数组中
int[] yunqi = new int[5];
for(int i = 0; i < yunqi.length; i++){
yunqi[i] = (int)(Math.random()*(max-min))+min;
}
System.out.print("请输入您的卡号:");
int yourcard = input.nextInt();
int i;
System.out.print("\n本日的幸运数字为:");
for (i = 0; i < yunqi.length; i++) {
System.out.print(yunqi[i] + " ");
}
for (i = 0; i < yunqi.length; i++) {
if (yunqi[i] == yourcard) {
System.out.println("\n恭喜!您是本日的幸运会员!");
break;
}
}
if (i == yunqi.length) {
System.out.println("\n抱歉!您不是本日的幸运会员!");
}
}
break;
default:
System.out.println("[您的输入有误!]");
break;
}
System.out.print("继续吗?(y/n):");
answer = input.next();
System.out.println("");
} while ("y".equals(answer));
if ("n".equals(answer)) {
System.out.println("系统退出,谢谢使用!");
}
}
}
|
|