package Java_project_1;
import java.util.Random;
import java.util.Scanner;
public class Java_project_1 {
public static void main(String[] args) {
int[] usrNumber=userInputNumber();
printArray(usrNumber);
System.out.println("中奖号码为:");
int[] luckNumber=createLuckNumber();
printArray(luckNumber);
judge(luckNumber,usrNumber);
}
public static void judge(int[] luckNumbers,int[] userNumbers){
int redHitNumbers=0;
int blueHitNumbers=0;
for (int i=0;i<userNumbers.length-1;++i){
for (int j=0;j<luckNumbers.length-1;++j){
if(userNumbers[i]==luckNumbers[j]){
++redHitNumbers;
break;
}
}
}
blueHitNumbers=luckNumbers[6]==userNumbers[6]?1:0;
System.out.println("你命中了" + redHitNumbers + "红球");
System.out.println("你" + (blueHitNumbers == 1 ? "是" : "否") + "命中蓝球");
if (redHitNumbers == 6 && blueHitNumbers == 1) {
System.out.println("恭喜您!中了一等奖~ 奖金1000万已入账~~");
} else if (redHitNumbers == 6 && blueHitNumbers == 0) {
System.out.println("恭喜您!中了二等奖~ 奖金500万已入账~~");
} else if (redHitNumbers == 5 && blueHitNumbers == 1) {
System.out.println("恭喜您!中了三等奖~ 奖金3000元已入账~~");
} else if ( (redHitNumbers == 5 && blueHitNumbers == 0) || (redHitNumbers == 4 && blueHitNumbers == 1) ) {
System.out.println("恭喜您!中了四等奖~ 奖金200元已入账~~");
} else if ( (redHitNumbers == 4 && blueHitNumbers == 0) || (redHitNumbers == 3 && blueHitNumbers == 1)) {
System.out.println("恭喜您!中了五等奖~ 奖金10元已入账~~");
} else if (redHitNumbers <3 && blueHitNumbers == 1) {
System.out.println("恭喜您!中了六等奖~ 奖金5元已入账~~");
}else {
System.out.println("感谢您为福利事业作出的伟大贡献!!");
}
}
public static void printArray(int[] arr){
for (int i=0;i< arr.length;++i){
System.out.print(arr[i] + "\t");
}
System.out.println();
}
public static int[] userInputNumber(){
int[] numbers=new int[7];
Scanner sc=new Scanner(System.in);
for(int i=0;i< numbers.length-1;++i){
System.out.println("请用户输入第" + i + "个红球号码(0-33不重复):");
numbers[i]=sc.nextInt();
}
System.out.println("请输入蓝球号码:");
numbers[numbers.length-1]= sc.nextInt();
return numbers;
}
public static int[] createLuckNumber(){
int[] numbers=new int[7];
Random r=new Random();
for(int i=0;i< numbers.length-1;++i){
while (true){
int data=r.nextInt(33)+1;
boolean flag=true;
for (int j=0;j<i;j++){
if(numbers[j]==data){
flag=false;
break;
}
}
if (flag) {
numbers[i]=data;
break;
}
}
}
numbers[numbers.length-1]= r.nextInt(16)+1;
return numbers;
}
}