HVERITAS

导航

7.10 作业 韩宗轩

  1 import java.util.Scanner;
  2 class SssGame {
  3 public static void main(String[] args) {
  4     int totalMoney = 0;
  5     int price = 2;
  6     int count = 0;
  7     boolean isBuy = false;
  8     int num[] = null;
  9     do{
 10     System.out.println("******欢迎进入双色球彩票系统******");
 11     System.out.println("\t 1.购买彩票");
 12     System.out.println("\t 2.查看开奖");
 13     System.out.println("\t 3.退出");
 14     System.out.println("*********************************");
 15     System.out.println("请选择菜单");
 16 
 17     Scanner input = new Scanner(System.in);
 18     int choice = input.nextInt();
 19     switch (choice) {
 20     case 1:
 21         System.out.println("[双色球系统--->购买彩票]");
 22         System.out.println("您需要下多少注? : ");  
 23         count = input.nextInt();
 24         totalMoney = count * price;
 25 
 26             num = new int[7];
 27             for (int i = 0; i < num.length;i++ ) {
 28                 int red;
 29                 int blue;
 30                 if (i < num.length - 1) {
 31                     System.out.println("请输入6个红色球号(数字为1-33),第" + (i + 1 )+"个红色球号码为:");
 32                     red = input.nextInt();
 33                     num[i] = red;
 34 
 35                 }else{
 36                     System.out.println("请输入1个蓝色球号,数字为(1-16):");
 37                     blue = input.nextInt();
 38                     num[i] = blue;
 39                 }
 40             }
 41             System.out.print("您一共买了"+ count + "注,共需支付"+totalMoney+"元,所选号为:");
 42             for (int i = 0;i < num.length ;i++ ) {
 43                 System.out.print(num[i]+"\t");
 44             }
 45 
 46             System.out.println();
 47             isBuy = true;
 48             break;
 49     case 2:
 50         System.out.println("[双色球彩票系统--->查看开奖]");
 51         isBuy = false;
 52         int luckNum[] = getLuckNum();
 53         System.out.print("已买的彩票号为: ");
 54         for (int n:num ) {
 55             System.out.print(n+"\t");
 56 
 57         }
 58         System.out.println();
 59         int result = getCompareResult(num,luckNum);
 60         if (result == 1) {
 61             System.out.println("一等奖,恭喜您!共下注了"+ count+"注,投资"+totalMoney+"元,获奖"+(500*count)+"万元");
 62 
 63         }else if (result==2) {
 64             System.out.println("二等奖,恭喜您!共下注了"+ count+"注,投资"+totalMoney+"元,获奖"+(400*count)+"万元");
 65         }
 66         else if (result==3) {
 67             System.out.println("三等奖,恭喜您!共下注了"+ count+"注,投资"+totalMoney+"元,获奖"+(300*count)+"万元");
 68         }
 69         else if (result==4) {
 70             System.out.println("四等奖,恭喜您!共下注了"+ count+"注,投资"+totalMoney+"元,获奖"+(200*count)+"万元");
 71         }
 72         else if (result==5) {
 73             System.out.println("五等奖,恭喜您!共下注了"+ count+"注,投资"+totalMoney+"元,获奖"+(100*count)+"万元");
 74         }
 75         else if (result==6) {
 76             System.out.println("六等奖,恭喜您!共下注了"+ count+"注,投资"+totalMoney+"元,获奖"+(5*count)+"万元");
 77         }else{
 78             System.out.println("望再接再励,sorry!!共下注了"+ count+"注,投资"+totalMoney+"元,获奖"+(0*count)+"万元");
 79         }
 80 
 81         break;
 82     case 3:
 83         System.out.println("谢谢使用");
 84         return;
 85     default:
 86         System.out.println("输入有误");
 87         break;
 88     }
 89     }while(true);
 90 
 91 }
 92 public static int[] getLuckNum(){
 93     int luckNum [] = new int[7];
 94     for (int i = 0;i< luckNum.length ;i++ ) {
 95         if (i<luckNum.length-1) {
 96             luckNum[i] = (int)(Math.random()*33 + 1);
 97         }else{
 98             luckNum[i] = (int)(Math.random()*16+1);
 99             }
100     }
101     return luckNum;
102 }
103 public static int getCompareResult(int num [],int luckNum[]){
104     int luckLevel = 0;
105     int redEqualCount = 0;
106     int blueEqualCount = 0;
107     for (int i = 0;i<num.length ;i++ ) {
108         if (i<num.length - 1) {
109             int r = num[i];
110             for (int j = 0;j<luckNum.length - 1 ;j++ ) {
111                 if (r==luckNum[j]) {
112                     redEqualCount++;
113                 }
114             }
115         }else{
116             if ((num[num.length-1])==luckNum[luckNum.length-1]) {
117                 blueEqualCount++;
118             }
119         }
120     }
121     if (redEqualCount==6&&blueEqualCount==1) {
122         luckLevel=1;
123     }else if (redEqualCount==6) {
124         luckLevel=2;
125     }
126     else if (redEqualCount==5&&blueEqualCount==1) {
127         luckLevel=3;
128     }
129     else if (redEqualCount==5||(redEqualCount==4&&blueEqualCount==1)) {
130         luckLevel=4;
131     }
132     else if (redEqualCount==4||(redEqualCount==4&&blueEqualCount==1)) {
133         luckLevel=5;
134     }
135     else if (blueEqualCount==1) {
136         luckLevel=2;
137     }
138     else if (redEqualCount==6) {
139         luckLevel=6;
140     }
141     return luckLevel;
142 }
143 }

 

posted on 2018-07-10 15:15  HVERITAS  阅读(307)  评论(0编辑  收藏  举报