Java 模擬福彩雙色球

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Test01 {
	
	public static void main(String[] args) {
		game lottery = new game();
		lottery.welcome();
		Scanner sca = new Scanner(System.in);
		
		while(true){
			int n=sca.nextInt();
			if(n==1){
				lottery.buyLottery();
			}
			if(n==2){
				lottery.getLottery();
			}
			if(n==3){
				break;
			}
			lottery.welcome();
		}
		System.out.println("*****退出,感謝使用*****");
		sca.close();
	}
}
class game{
	
	private int buyMoney;
	private int getMoney;
	private int[] buyRed;
	private int buyBlue;
	private int[] lotteryRed;
	private int lotteryBlue;
	
	public game() {
		this.buyMoney = 0;
		this.getMoney = 0;
		buyRed=null;
		lotteryRed=null;
	}
	public void countMoney(int redCount){
		if(redCount==6&&buyBlue==lotteryBlue){
			System.out.println("一等獎");
			getMoney+=5000000;
		}
		else if(redCount==6&&buyBlue!=lotteryBlue){
			System.out.println("二等獎");
			getMoney+=1000000;
		}
		else if(redCount==5&&buyBlue==lotteryBlue){
			System.out.println("三等獎");
			getMoney+=3000;
		}
		else if((redCount==5&&buyBlue!=lotteryBlue)||(redCount==4&&buyBlue==lotteryBlue)){
			System.out.println("四等獎");
			getMoney+=200;
		}
		else if((redCount==4&&buyBlue!=lotteryBlue)||(redCount==3&&buyBlue==lotteryBlue)){
			System.out.println("五等獎");
			getMoney+=10;
		}
		else if(buyBlue==lotteryBlue){
			System.out.println("六等獎");
			getMoney+=5;
		}
	}
	public void welcome(){
		System.out.println("*****歡迎進入雙色球彩票系統*****");
		System.out.println("       1.購買彩票");
		System.out.println("       2.查看開獎");
		System.out.println("       3.退出");
		System.out.println("*************************");
		System.out.print("選擇菜單:");
	}
	public void buyLottery(){
		buyRed = new int[6];
		System.out.print("請輸入你的購彩號碼,以空格隔開:");
		Scanner in =new Scanner(System.in);
		for(int i=0;i<6;i++){
			buyRed[i]=in.nextInt();
		}
		buyBlue = in.nextInt();
		Arrays.sort(buyRed);
		buyMoney+=2;
	}
	public void getLottery(){
		if(buyRed!=null||buyBlue!=0){
			lotteryRed = new int[6];
			Random r = new Random();
			System.out.print("購彩號碼爲:");
			for(int i=0;i<6;i++){
				System.out.print(buyRed[i]+" ");
				lotteryRed[i]=r.nextInt(33)+1;
			}
			System.out.println(buyBlue);
			lotteryBlue = r.nextInt(16)+1;
			Arrays.sort(lotteryRed);
			int redCount=0;
			System.out.print("開獎號碼爲:");
			for(int i=0;i<6;i++)
			{
				System.out.print(lotteryRed[i]+" ");
				if(buyRed[i]==lotteryRed[i]){
					redCount++;
				}
			}
			System.out.println(lotteryBlue);
			countMoney(redCount);
			System.out.println("你一共下注"+buyMoney+"元"+"你一共中獎"+getMoney+"元");
			buyRed=null;
			buyBlue=0;
		}
		else
		{
			System.out.println("沒有購買彩票不能開獎");
		}
		
	}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章