幸运抽奖案例
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沒有中獎呢");}}
總結
- 上一篇: 穿越火线电脑配置要求?
- 下一篇: CF职业玩家的电脑配置是?