三色球小游戏实验

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;
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();
break;
case 2:
System.out.println("[双色球系统 > 查看开奖]");
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;
}


}

• 点赞
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 打赏

打赏

weixin_43392244

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 举报
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文
03-01 189
10-10 1319

09-28 42万+
09-23 19万+
05-28 161
10-27 652
07-17 284