First Project--幸运抽奖

public class LuckDemo {

	static boolean isRegist = false;// 是否注册
	static boolean isLogin = false;// 是否登录
	static int errors = 0;// 登录错误的次数
	static String name;// 注册的用户名
	static String password;// 注册的密码

	public static void main(String[] args) {
		/**
		 * 幸运抽奖
		 */

		
		Scanner sc = new Scanner(System.in);
		
		selectMenu(sc);

	}

	/**
	 * 选择菜单
	 */
	private static void selectMenu(Scanner sc) {
		System.out.println("********欢迎进入奖客富翁系统**********");
		System.out.println("           1.注册");
		System.out.println("           2.登录");
		System.out.println("           3.抽奖");
		System.out.println("*********************************");
		
		System.out.print("请选择菜单:");
		String key = sc.next();
		switch (key) {
		case "1": // 注册
			regist(sc);
			break;
		case "2":// 登录
			if (isRegist) {// 注册了才能登录
				System.out.println("[奖客富翁系统 > 登录]");
				login(sc);
			} else {
				System.err.println("请选注册再登录");
				selectMenu(sc);
				//regist(sc);
			}

			break;
		case "3":// 抽奖
			if (isLogin) {
				chouJiang(sc);
			} else {
				System.err.println("请选登录再抽奖");
				selectMenu(sc);
			}

			break;
		default:
			System.out.println("输入有误,请重新选择菜单");
			selectMenu(sc);
			break;
		}

		isContinue(sc);
	}

	/**
	 * 抽奖
	 * 
	 * @param sc
	 */
	private static void chouJiang(Scanner sc) {
		System.out.println("[奖客富翁系统 > 抽奖]");
		System.out.println("请输入您的会员卡号:");
		int card = sc.nextInt();

		// 生成今日幸运卡号
		int card1 = (int) (Math.random() * 9000 + 1000);
		int card2 = (int) (Math.random() * 9000 + 1000);
		int card3 = (int) (Math.random() * 9000 + 1000);
		int card4 = (int) (Math.random() * 9000 + 1000);
		int card5 = (int) (Math.random() * 9000 + 1000);
		System.out.println("今日运行号码为:" + card1 + " " + card2 + " " + card3 + " " + card4 + " " + card5);
		if (card == card1 || card == card2 || card == card3 || card == card4 || card == card5) {
			System.out.println("恭喜中了500万!");
		} else {
			System.out.println("很遗憾请再接再厉!");
		}
	}

	/**
	 * 登录
	 * 
	 * @param sc
	 */
	private static void login(Scanner sc) {
		System.out.println("请输入登录的用户名:");
		String userName = sc.next();
		System.out.println("请输入登录的密码:");
		String pwd = sc.next();

		if (userName.equals(name) && pwd.equals(password)) {// 登录成功
			System.out.println("欢迎您:" + name);
			isLogin = true;
		} else {// 登录失败
			errors++;
			if (errors == 3) {
				System.out.println("您今天输入密码次数太多,请明天再试!");
				System.exit(0);
			} else {
				System.out.println("用户名或密码输入有误,请重新输入!" +(3-errors));
				login(sc);
				
			}
		}
	}

	/**
	 * 注册
	 * 
	 * @param sc
	 */
	private static void regist(Scanner sc) {
		System.out.println("[奖客富翁系统 > 注册]");
		// 用户名
		System.out.print("请输入注册的用户名:");
		name = sc.next();
		// 密码
		System.out.print("请输入注册的密码:");
		password = sc.next();

		// 会员卡号
		int card = (int) (Math.random() * 9000 + 1000);

		System.out.println("注册成功,请记住您的会员卡号:");
		System.out.println("用户名\t 密码\t 会员卡号");
		System.out.println(name + "\t " + password + "\t" + card);
		isRegist = true;
	}

	/**
	 * 是否继续
	 * 
	 * @param sc
	 */
	private static void isContinue(Scanner sc) {
		System.out.println("是否继续?(y/n)");
		String yes = sc.next();// 默认值为null
		if ("y".equalsIgnoreCase(yes)) {
			selectMenu(sc);
		} else {// 退出系统
			System.exit(0);
		}
	}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值