幸运抽奖
此章没有什么知识点,所用到的都是之前学过的东西,
可能会有bug,答案仅供参考;
import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int xvanze = 0;
String username = null;
String password = null;
int cardnumber;
int max = 9999;
int min = 1000;
boolean isreg = false;
boolean islucky = false;
boolean is = false;
String a = "y";
do {
System.out.println("*************欢迎进入奖客富翁系统*************");
System.out.println("\t\t\t1.注册");
System.out.println("\t\t\t2.登录");
System.out.println("\t\t\t3.抽奖");
System.out.println("***************************************");
System.out.print("请选择菜单");
xvanze = sc.nextInt();
switch (xvanze) {
case 1:
System.out.println("[奖客富翁系统:>注册]");
System.out.println("请填写个人注册信息");
System.out.print("用户名:");
username = sc.next();
System.out.print("密码:");
password = sc.next();
cardnumber = (int) (Math.random() * (max - min)) + min;
System.out.println("注册成功,请记好您的会员卡号");
System.out.println("用户名" + "\t密码" + "\t会员卡号");
System.out.println(username + "\t" + password + "\t" + cardnumber);
isreg = true;
break;
case 2:
System.out.println("[奖客富翁系统:>登录]");
if (isreg) {
for (int i = 3; i > 0; i--) {
System.out.print("请输入用户名");
String name = sc.next();
System.out.print("请输入密码");
String pass = sc.next();
if (name.equals(username) && pass.equals(password)) {
System.out.println("欢迎你:" + username);
islucky = true;
break;
} else if (i == 1) {
System.out.println("3次机会已用完");
return;
} else {
System.out.println("输入错误,还有" + (i - 1) + "次机会");
}
}
} else {
System.out.println("请先注册");
}
break;
case 3:
System.out.println("[奖客富翁系统:>抽奖]");
if (islucky) {
System.out.print("请先输入您的卡号");
int card = sc.nextInt();
int c[] = new int[5];
for (int i = 0; i < c.length; i++) {
c[i] = (int) (Math.random() * (max - min)) + min;
System.out.print(c[i] + "\t");
if (c[i] == card) {
is = true;
}
}
System.out.println();
if (is) {
System.out.println("恭喜您,成为今天的幸运会员");
} else {
System.out.println("抱歉您不是本日的幸运会员");
}
} else {
System.out.println("请先登录");
}
break;
default:
System.out.println("输入错误!");
continue;
}
System.out.println("继续吗?(y/n)");
a = sc.next();
} while ("y".equals(a));
if (!("y".equals(a))) {
System.out.println("系统推出,谢谢使用!");
}
}
}