import java.util.Scanner;

class SsqGame {
public static void main(String[] args) {
int total = 0;//买了几注
int[] num = new int[7];
boolean flag = false;
do{
System.out.println("*****欢迎进入双色球彩票系统*****");
System.out.println(" 1.购买彩票 ");
System.out.println(" 2.查看开奖 ");
System.out.println(" 3.退出 ");
System.out.println("********************************");
Scanner sc = new Scanner(System.in);
System.out.println("请选择菜单:");
int choice = sc.nextInt();
switch (choice) {
case 1:
System.out.println("请选择您要购买几注彩票:");
int record = sc.nextInt();
total = record * 2;
for (int i = 0;i < 7 ;i++ ) {
if (i < 6) {
System.out.println("购买红色球,请选择一个1-33之间的号码:");
int red = sc.nextInt();
num[i] = red;
}else{
System.out.println("购买蓝色球,请选择一个1-16之间的号码:");
int blue = sc.nextInt();
num[i] = blue;
}
}
System.out.print("您一共购买了" + record + "注,共需支付" + total + "元,您所选号码为:");
print(num);
System.out.println(); break;
case 2:
//随机生成开奖号码
int luckNum[] = getLuckNum();
System.out.print("本次中奖号码为:");
print(luckNum);
System.out.print("已买的彩票号:");
print(num);
//比较中奖号码和已买号码
int result = resultComparation(num,luckNum);
System.out.println("中奖信息:");
if (result == 1) {
System.out.println("恭喜您中了一等奖!");
}else if (result == 2) {
System.out.println("恭喜您中了二等奖!");
}else if (result == 3) {
System.out.println("恭喜您中了三等奖!");
}else if (result == 4) {
System.out.println("恭喜您中了四等奖!");
}else if (result == 5) {
System.out.println("恭喜您中了五等奖!");
}else if (result == 6) {
System.out.println("恭喜您中了六等奖!");
}else{
System.out.println("很遗憾没有中奖");
}
System.out.println(); break;
case 3:
flag = true;
break;
default:
System.out.println("请输入正确的选项");
break; }
}while(true);
} public static void print(int[] arr){
for (int i = 0;i < arr.length ;i++ ) {
System.out.print(arr[i] + " ");
}
} public static int[] getLuckNum(){
int luckNum[] = new int[7];
for (int i = 0;i < luckNum.length ;i++ ) {
if (i < luckNum.length - 1) {
a:for (int j = 0;j < luckNum.length-i ;j++ ) {
int m = (int)(Math.random()*33 + 1);
if (m != luckNum[j]) {
luckNum[j] = m;
}
else{
break a;
}
}
}else{
luckNum[i] = (int)(Math.random()*16 + 1);
}
}
return luckNum;
} public static int resultComparation(int[] num,int[] luckNum){
int redcount = 0;//红球相同个数
int bluecount = 0;//蓝球相同个数
int result = 0;//中奖等级
//将所买号码中每个数字与中奖号码进行比较,计算红球和蓝球各自相同的个数
for (int i = 0;i < num.length ;i++ ) {
if (i < num.length - 1) {
int m = num[i];
for (int j = 0;j < luckNum.length - 1 ;j++ ) {
if (m == luckNum[j]) {
redcount++;
}
}
}else{
if (num[num.length-1] == luckNum[luckNum.length-1]) {
bluecount++;
}
}
}
//确定中奖等级
if (redcount == 6 && bluecount == 1) {
result = 1;
}else if (redcount == 6 && bluecount == 0) {
result = 2;
}else if (redcount == 5 && bluecount == 1) {
result = 3;
}else if ((redcount == 5 && bluecount == 0) ||(redcount == 4 && bluecount == 1)) {
result = 4;
}else if ((redcount == 4 && bluecount == 0) ||(redcount == 3 && bluecount == 1)) {
result = 5;
}else if (redcount == 0 && bluecount == 1) {
result = 6;
}else{
result = 0;
}
return result;
}
}
05-11 20:13