import java.util.Random;
import java.util.Scanner;
class java20221217 {
public static void main(String[] args) {
//红球 1-33 中选择6个 / 篮球 1-16 中选择1个
//生成中将号码
int[] arrNumber = create();
//录入用户输入的红蓝球
int[] userInput = getUserInput();
//得到红球中奖个数
int redCount = getRedCount(arrNumber,userInput);
//得到篮球中将个数
int blueCount = getBlueCount(arrNumber,userInput);
System.out.println("\n红球中奖个数: " + redCount);
System.out.println("蓝球中奖个数: " + blueCount);
//判断中奖级别
String result = getResult(redCount, blueCount);
System.out.println(result);
//查看生成的数据
System.out.println("中奖号码为: ");
for (int i : arrNumber) {
System.out.print(i + " ");
}
System.out.println();
System.out.println("我输入的号码为: ");
for (int j : userInput) {
System.out.print(j + " ");
}
System.out.println();
}
public static boolean contains(int[] arr, int number) {
for (int i : arr) {
if(i == number) {
return true;
}
}
return false;
}
public static int[] create() {
Random random = new Random();
int[] createResult = new int[7]; //存放生成的号码
for(int i=0;i<6;){
int redNumber = random.nextInt(33)+1;
if(!contains(createResult, redNumber)) {
createResult[i] = redNumber;
i++;
}
}
int blueNumber = random.nextInt(16)+1;
createResult[6] = blueNumber;
return createResult;
}
public static int[] getUserInput() {
int[] userInput = new int[7]; //存放用户输入
Scanner sc = new Scanner(System.in);
for(int i=0;i<6;) {
System.out.print("请输入第" + (i+1) + "个红色球号码: ");
int input = sc.nextInt();
if(!contains(userInput,input)){
if(input >= 1 && input <= 33){
userInput[i] = input;
i++;
}else{
System.out.println("请输入正确的红色球号码");
}
}else{
System.out.println("这个号码已经选择过了");
}
}
for(int j=0;j<1;) {
System.out.print("请输入蓝色球号码: ");
int input = sc.nextInt();
if(input >= 1 && input <= 16){
userInput[userInput.length-1] = input;
j++;
}else{
System.out.println("请输入正确的蓝色球号码");
}
}
return userInput;
}
public static int getRedCount(int[] arr,int[] userInput) {
int count = 0;
for(int i=0;i<arr.length-1;i++) {
if(arr[i] == userInput[i]) {
count++;
}
}
return count;
}
public static int getBlueCount(int[] arr,int[] userInput) {
if(arr[arr.length-1] == userInput[userInput.length-1]) {
return 1;
}else{
return 0;
}
}
public static String getResult(int redCount, int blueCount) {
if(redCount == 6 && blueCount == 1){
return "一等奖,中奖1000万";
}else if(redCount == 6 && blueCount == 0){
return "二等奖,中奖500万";
}else if(redCount == 5 && blueCount == 1){
return "三等奖,中奖3000";
}else if((redCount == 5 && blueCount == 0) || (redCount == 4 && blueCount == 1)){
return "四等奖,中奖200元";
}else if((redCount == 4 && blueCount == 0) || (redCount == 3 && blueCount == 1) || (redCount == 2 && blueCount == 1)){
return "五等奖,中奖10元";
}else if((redCount == 1 && blueCount == 0) || blueCount == 1){
return "六等奖,中奖5元";
}
return "未中奖";
}
}