幸运抽奖案例

package xinyunchoujiang;

import java.util.Scanner;


/**
 * 
*    
* 项目名称:19qn3   
* 类名称:CaiDan   
* 类描述: 幸运抽奖  
* 创建人:Mu Xiongxiong  
* 创建时间:2020-4-2 下午5:13:15   
* 修改人:Mu Xiongxiong   
* 修改时间:2020-4-2 下午5:13:15   
* 修改备注:   
* 个人博客:https://blog.csdn.net/qq_34137397
* @version    
*
 */
public class CaiDan {
	static Scanner sc = new Scanner(System.in);
	static String name = "";
	static String pass = "";
	static int random = 0;
	static boolean isReg = false;	//是否注册
	static boolean isLogin = false;	//是否登陆
	static int [] jiang = new int [4];	//随机中奖客户
	public static void main(String[] args) {
		menu();
	}

	// 菜单的方法
	public static void menu() {
		Scanner sc = new Scanner(System.in);
		String ji = "";
		do {
			System.out.println("*****欢迎进入奖客富翁系统*****");
			System.out.println("\t1.注册");
			System.out.println("\t2.登录");
			System.out.println("\t3.抽奖");
			System.out.println("***************************");
			System.out.print("请选择菜单:");
			int choice = sc.nextInt();
			switch (choice) {
			case 1:
				System.out.println("[奖客富翁系统 > 注册]");
				reg();
				break;
			case 2:
				System.out.println("[奖客富翁系统 > 登录]");
				login();
				break;
			case 3:
				System.out.println("[奖客富翁系统 > 抽奖]");
				if(isLogin==true){
					choujiang();
				}else{
					System.out.println("还没登陆呢,请登录");
				}
				break;
			default:
				System.out.println("[您的输入有误!]");
				break;
			}
			System.out.println("继续吗?(y/n)");
			ji = sc.next();
		} while (ji.equals("y"));
		System.out.println("已经退出!!!");
	}

	//注册
	public static void reg() {
		System.out.println("请输入用户名:");
		name = sc.next();
		System.out.println("请输入密码:");
		pass = sc.next();
		random = (int) (Math.random() * 10000);
		System.out.println("用户名\t密码\t会员卡号");
		System.out.println(name + "\t" + pass + "\t" + random);
		isReg = true;
	}

	//登陆
	public static void login(){
		if(isReg==true){
			for(int i = 1;i<=3;i++){
				System.out.println("请输入用户名:");
				String name1 = sc.next();
				System.out.println("请输入密码:");
				String pass1 = sc.next();
				if(name1.equals(name)&&pass1.equals(pass)){
					System.out.println("登录成功");
					isLogin = true;
					break;
				}else if(i<3){
					System.out.println("还有"+(3-i)+"次机会");
				}else{
					System.out.println("没有机会了");
				}
			}
		}else{
			System.out.println("还没有注册呢");
		}
		
		
	}

	//抽奖
	public static void choujiang(){
		System.out.println("请输入您的卡号:");
		int kahao = sc.nextInt();
		for(int i = 0;i<4;i++){
			jiang[i] = (int)(Math.random()*10000);
		}
		System.out.println("中奖的卡号是:");
		for (int i : jiang) {
			System.out.print(i+"\t");
		}
		for (int i = 0; i < jiang.length; i++) {
			if(kahao==jiang[i]){
				System.out.println("您中奖啦");
				break;
			}
		}
		System.out.println("\n没有中奖呢");
	}
	
}

posted @ 2020-04-02 17:17  穆雄雄  阅读(140)  评论(0编辑  收藏  举报