java学习第九天 作业3D彩票系统

package com.lanou;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class NaQian02 {
    public static void main(String[] args) {
        System.out.println("--------华丽的分割线---------");
        System.out.println("1.查看余额");
        System.out.println("2.充值");
        System.out.println("3.自选");
        System.out.println("4.机选");
        System.out.println("5.查看购买彩票");
        System.out.println("6.开奖");
        System.out.println("0.退出");

        int a = 2000000;// 账户余额
        int[][] arrayzixuan0 = new int[0][3];
        int[][] arrayjixuan0 = new int[0][3];
        int[][] arrayzixuan1 = new int[0][3];
        int[][] arrayjixuan1 = new int[0][3];
        Scanner sc = new Scanner(System.in);
        boolean flag = true;
        while (flag) {
            System.out.println("请输入您的选择:");
            int num = sc.nextInt();
            switch (num) {
            case 1:// 功能一
                System.out.println("当前账户余额为:" + a);
                break;

            case 2:// 功能二
                System.out.println("充值活动:充50送20,充100送50,充500送300");
                System.out.println("请输入充值额度:");
                int b = sc.nextInt();
                if (b >= 50 && b < 100) {
                    a = a + b + 20;
                } else if (b >= 100 && b < 500) {
                    a = a + b + 50 * (b / 100);
                } else {
                    a = a + b + 300 * (b / 500);
                }
                System.out.println("充值成功!当前余额是" + a + "¥");
                break;

            case 3:// 功能三
                System.out.println("请输入自选注数:");
                int d = sc.nextInt();// 多少注
                System.out.println("请输入购买彩票的类型:(0.直选 1.组六)");
                int c = sc.nextInt();
                if (c == 0) {
                    System.out.println("请输入您的号码(三个0~9的自然数):");
                    int[][] array00 = new int[d][3];
                    for (int i = 0; i < d; i++) {
                        for (int j = 0; j < 3; j++) {
                            array00[i][j] = sc.nextInt();
                        }
                        arrayzixuan0 = array00;
                    }
                } else if (c == 1) {

                    if (d > 0 && a >= d * 2) {
                        a = a - d * 2;
                        System.out.println("请输入您的号码(三个0~9的自然数):");
                        int[][] array01 = new int[d][3];
                        for (int i = 0; i < d; i++) {
                            for (int j = 0; j < 3; j++) {
                                array01[i][j] = sc.nextInt();
                            }
                            arrayzixuan1 = array01;
                        }
                    }
                    System.out.println("购买成功");
                }

                break;

            case 4:// 功能四
                System.out.println("请输入机选注数:");
                int e = sc.nextInt();
                System.out.println("请输入购买彩票的类型:(0.直选 1.组六)");
                int c1 = sc.nextInt();
                if (c1 == 0) {
                    if (e > 0 && a >= e * 2) {
                        a = a - e * 2;
                        Random random = new Random();
                        int[][] array02 = new int[e][3];
                        for (int i = 0; i < e; i++) {
                            for (int j = 0; j < 3; j++) {
                                array02[i][j] = random.nextInt(10);
                            }
                            arrayjixuan0 = array02;
                            System.out.println(Arrays.toString(arrayjixuan0[i]));
                        }
                    }

                } else if (c1 == 1) {
                    if (e > 0 && a >= e * 2) {
                        a = a - e * 2;
                        Random random = new Random();
                        int[][] array03 = new int[e][3];
                        for (int i = 0; i < e; i++) {
                            for (int j = 0; j < 3; j++) {
                                array03[i][j] = random.nextInt(10);
                            }
                            arrayjixuan1 = array03;
                            System.out.println(Arrays.toString(arrayjixuan1[i]));
                        }
                        System.out.println("购买成功");
                    }
                }
                break;

            case 5:
                System.out.println("您购买的彩票号码如下:");
                System.out.println("直选");
                for (int i = 0; i < arrayzixuan0.length; i++) {
                    System.out.print("[");
                    for (int j = 0; j < 3; j++) {
                        System.out.print(arrayzixuan0[i][j] + " ");
                    }
                    System.out.println("]");
                }
                System.out.println(" ");
                
                for (int i = 0; i < arrayjixuan0.length; i++) {
                    System.out.print("[");
                    for (int j = 0; j < 3; j++) {
                        System.out.print(arrayjixuan0[i][j] + " ");
                    }
                    System.out.println("]");
                }
                System.out.println(" ");
                
                

                
                System.out.println("组六");
                for (int i = 0; i < arrayzixuan1.length; i++) {
                    System.out.print("[");
                    for (int j = 0; j < 3; j++) {
                        System.out.print(arrayzixuan1[i][j] + " ");
                    }
                    System.out.println("]");
                }
                System.out.println(" ");
                
                
                for (int i = 0; i < arrayjixuan1.length; i++) {
                    System.out.print("[");
                    for (int j = 0; j < 3; j++) {
                        System.out.print(arrayjixuan1[i][j] + " ");
                    }
                    System.out.println("]");
                }
                System.out.println(" ");
                break;

            case 6:
                Random random=new Random();
                int[] lucky = new int[3];// 生成一注中奖码
                for (int j = 0; j < 3; j++) {
                    lucky[j] = random.nextInt(10);
                }
                System.out.println("当前彩票中奖码是:" + Arrays.toString(lucky));

                int sum = 0;
                int sum1= 0;
                int sum2=0;
                int sum3=0;
                for(int i=0;i<arrayzixuan0.length;i++) {
                    int count = 0;
                    for(int j=0;j<arrayzixuan0[i].length;j++) {
                        if(arrayzixuan0[i][j] == lucky[j]) {
                            count++;
                        }
                    }
                    System.out.println("当前彩票号码:"+Arrays.toString(arrayzixuan0[i])+" 相同彩票个数为:"+count+" 中奖金额为:"+(count==3 ? 1000 : 0));
                    sum += (count==3 ? 1000 : 0);
                }
                System.out.println("此次自选直选彩票中奖总额为:"+sum);
                
                for(int i=0;i<arrayjixuan0.length;i++) {
                    int count1 = 0;
                    for(int j=0;j<arrayjixuan0[i].length;j++) {
                        if(arrayjixuan0[i][j] == lucky[j]) {
                            count1++;
                        }
                    }
                    System.out.println("当前彩票号码:"+Arrays.toString(arrayjixuan0[i])+" 相同彩票个数为:"+count1+" 中奖金额为:"+(count1==3 ? 1000 : 0));
                    sum1 += (count1==3 ? 1000 : 0);
                }
                System.out.println("此次机选直选彩票中奖总额为:"+sum1);
                
                Arrays.sort(lucky);
                for(int i=0;i<arrayzixuan1.length;i++) {
                    int count2 = 0;
                    for(int j=0;j<arrayzixuan1[i].length;j++) {
                        Arrays.sort(arrayzixuan1[i]);
                        if(arrayzixuan1[i][j] == lucky[j]) {
                            count2++;
                        }
                    }
                    System.out.println("当前彩票号码:"+Arrays.toString(arrayzixuan1[i])+" 相同彩票个数为:"+count2+" 中奖金额为:"+(count2==3 ? 1000 : 0));
                    sum2 += (count2==3 ? 166 : 0);
                }
                System.out.println("此次自选组六彩票中奖总额为:"+sum2);
                
                Arrays.sort(lucky);
                for(int i=0;i<arrayjixuan1.length;i++) {
                    int count3 = 0;
                    for(int j=0;j<arrayjixuan1[i].length;j++) {
                        Arrays.sort(arrayjixuan1[i]);
                        if(arrayjixuan1[i][j] == lucky[j]) {
                            count3++;
                        }
                    }
                    System.out.println("当前彩票号码:"+Arrays.toString(arrayjixuan1[i])+" 相同彩票个数为:"+count3+" 中奖金额为:"+(count3==3 ? 166 : 0));
                    sum3 += (count3==3 ? 166 : 0);
                }
                System.out.println("此次机选组六彩票中奖总额为:"+sum3);

                break;

            case 0:
                flag = false;
                System.out.println("欢迎再来给钱");
            default:

            }

        }

    }

}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值