三色球小游戏实验

package Java_study;

import java.util.Scanner;
public class SSQYX {
public static void main(String[] args) {
int totalMoney = 0;
int price = 2;
int count = 0;
boolean isBuy = false;
int num[] = null;
Scanner sc = new Scanner(System.in);
do{
System.out.println(“欢迎进如双色球彩票系统”);
System.out.println(" 1.购买彩票 “);
System.out.println(” 2.查看开奖 “);
System.out.println(” 3.退出 “);
System.out.println(”*****************************");
System.out.println(“请选择菜单:”);
int choice = sc.nextInt();
switch (choice){
case 1:
//购买彩票
System.out.println(“购买彩票”);
System.out.println(“您需要下多少注?:”);
count = sc.nextInt();
totalMoney = pricecount;
//选号
num = new int[7];
for (int i =0;i<num.length;i++){
int red;
int blue;
if(i<num.length-1){
System.out.println(“请输入红色球号(数字为1-33),第【”+i+"】个红色球号为:");
red = sc.nextInt();
while(red>33||red<=0){
System.out.println(“彩票号码输入错误,请重新输入号码:第【”+i+"】个红色球号为:");
red = sc.nextInt();
}
num[i] = red;
}else {
System.out.println(“请输入绿色球号(数字为1-16):”);
blue = sc.nextInt();
while(blue>33||blue<=0){
System.out.println(“彩票号码输入错误,请重新输入号码:绿色球号(数字为1-16):”);
blue = sc.nextInt();
}
num[i] = blue;
}
}
System.out.println(“您一共买了【”+count+"】注,共需要支付【"+totalMoney+"】元,所选号为:");
for (int i=0;i<num.length;i++){
System.out.println(num[i]+"\t");
}
System.out.println();
isBuy = true;
break;
case 2:
System.out.println("[双色球系统 > 查看开奖]");
if(isBuy){ //购买了彩票
isBuy = false;// 开奖之后需要重新购买
int LuckNum[] = getLuckNum();
System.out.println(“已购买的彩票号为:”);
for(int n:num){
System.out.println(n+"\t");
}
System.out.println();
System.out.println(“当前的中奖号为:”);
for (int n:LuckNum){
System.out.println(n+"\t");
}
int result = getCompareResult(num,LuckNum);
if(result==1){
System.out.println("【一等奖】,恭喜你!共下了【"+count+"】注,投资【"+totalMoney+"】元,获奖【"+(500
count)+"】元");
}else if (result2){
System.out.println("【二等奖】,恭喜你!共下了【"+count+"】注,投资【"+totalMoney+"】元,获奖【"+(400*count)+"】元");
}else if (result
3){
System.out.println("【三等奖】,恭喜你!共下了【"+count+"】注,投资【"+totalMoney+"】元,获奖【"+(300count)+"】元");
}else if (result==4){
System.out.println("【四等奖】,恭喜你!共下了【"+count+"】注,投资【"+totalMoney+"】元,获奖【"+(200
count)+"】元");
}else if (result5){
System.out.println("【五等奖】,恭喜你!共下了【"+count+"】注,投资【"+totalMoney+"】元,获奖【"+(100*count)+"】元");
}else if (result
6){
System.out.println("【六等奖】,恭喜你!共下了【"+count+"】注,投资【"+totalMoney+"】元,获奖【"+(5*count)+"】元");
}else {
System.out.println("【望再接再厉】,sorry!!共下了【"+count+"】注,投资【"+totalMoney+"】元,获奖【"+0+"】元");
}
}else {
System.out.println(“请先购买彩票,再查看开奖情况!”);
}
break;
case 3:
System.out.println(“谢谢使用!”);
return;
}

    }while(true);
}
private static int[] getLuckNum() {
    int[] luckNum = new int[7];
    for (int i =0;i<luckNum.length;i++){
        if (i<luckNum.length-1){
            luckNum[i] = (int)(Math.random()*33)+1;
        }else {
            luckNum[i] = (int)(Math.random()*16)+1;
        }
    }
    return luckNum;
}
private static int getCompareResult(int[] num, int[] luckNum) {
    int luckleavel = 0;
    int redEqualsCount = 0;
    int blueEqualsCount = 0;

    for (int i =0;i<num.length;i++){
        if (i<num.length-1){
            int r = num[i];
            for (int j=0;j<luckNum.length-1;j++){
                if (r==luckNum[j]){
                    redEqualsCount++;
                }
            }

        }else {
            if (num[num.length-1] == luckNum[luckNum.length-1]){
                blueEqualsCount++;
            }
        }
    }
    if (redEqualsCount==6&&blueEqualsCount==1){
        luckleavel=1;
    }else if (redEqualsCount==6){
        luckleavel=2;
    }else if(redEqualsCount==5&&blueEqualsCount==1) {
        luckleavel=3;
    }else if (redEqualsCount==5||(redEqualsCount==4&&blueEqualsCount==1)){
        luckleavel=4;
    }else if ((redEqualsCount==4)||(redEqualsCount==3&&blueEqualsCount==1)){
        luckleavel=5;
    }else if (blueEqualsCount==1){
        luckleavel=6;
    }
    return luckleavel;
}

}

©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页