`import java.util.Arrays;
import java.util.Scanner;
/**
@Author:TJ
@Version:1.0
@Date:2022/4/30-17:15
@Since:jdk1.8
@Description:
*/
public class Work {
static String inputname, inputPswd;
static String loginname, loginPswd;
static Scanner scanner = new Scanner(System.in);
static int luckNum, num1;
static boolean flag;
public static void reg() {
System.out.println("请输入注册的账号");
inputname = scanner.next();
System.out.println("请输入注册的账号密码");
inputPswd = scanner.next();
System.out.println("注册成功!请记住你的密码");
luckNum = (int) (Math.random() * 8999 + 1000);
System.out.println("用户名" + "\t" + "密码" + "\t" + "会员卡号");
System.out.println(inputname + "\t" + "\t" + " " + inputPswd + "\t" + "\t" + luckNum);
}
public static void login() {
//先判断是否注册
if (inputname == null) {
System.out.println("你还未注册!");
return;
}
boolean flag = true;
int count = 3;
while (flag) {
System.out.println("请输入你的账号和密码");
loginname = scanner.next();
loginPswd = scanner.next();
if (inputname.equals(loginname) && inputPswd.equals(loginPswd)) {
System.out.println("登陆成功!");
break;
} else {
System.out.println("登陆失败!你还有" + (count - 1) + "次机会");
count--;
if (count == 0) {
System.out.println("次数用尽");
return;
}
} }
}
public static void again() {
String answer = "y";
System.out.println("请选择是否继续?请按 y , 按n退出本系统");
char a = scanner.next().charAt(0);
// switch (answer){
// case "y":
// break;
// case "n":
// System.out.println("谢谢使用!");
// return;
// }
if (a == 'y'||a=='Y') {
flag=true;
}else {
System.out.println("谢谢使用!");
return;
}
}
public static void menu() { System.out.println("***********欢迎进入奖客大富翁系统*************"); flag = true; while (flag) { System.out.println(" ************************************"); System.out.println("\t\t\t" + "1.注册账号"); System.out.println("\t\t\t" + "2.登录账号"); System.out.println("\t\t\t" + "3.超级抽奖"); System.out.println(" ************************************"); int choose = scanner.nextInt(); switch (choose) { case 1: reg(); flag = false; break; case 2: login(); flag = false; break; case 3: luck(); flag = false; break; default: System.out.println("选择有误,请重新选择"); break; } again(); } } public static void luck() { if (loginname == null) { System.out.println("你还未登录!"); return; } //随机生成四个四位数作为当日幸运数字 int[] luckDayNum = new int[5]; for (int i = 0; i < luckDayNum.length; i++) { luckDayNum[i] = (int) ((Math.random() * 8999 + 1000)); }
// boolean flag = true;
// while (flag) {
//判断用户输入的卡号和注册给的卡号是否一致
System.out.println("请输入您的卡号!");
num1 = scanner.nextInt();
if (num1 != luckNum) {
System.out.println("此数不是您的卡号!");
return;
// flag = true;
}
// break;
// }
// }
//判断用户是否是今日幸运客户
for (int i = 0; i < luckDayNum.length - 1; i++) {
if (luckDayNum[i] == num1) {
System.out.println("恭喜你!你中了十亿!");
break;
}
}
System.out.println("很抱歉,您不是我们的今日幸运会员!");
System.out.println("今日幸运数字是:" + Arrays.toString(luckDayNum));
}
public static void main(String[] args) { menu(); }
}`