基于JAVASE的彩票摇号系统

模拟双色球彩票系统
1. 双色球规则:
a) 双色球分为红球和蓝球,红球选择的范围为 1-33 而且红球选择 6 个数字,蓝球 1-16 而且只能选择一个。
b) 选择方式为 随机选择和手动输入选择号码。
c) 生成号码的顺序是由小到大。
2. 功能描述
首先系统能够让用户选择随机选择和手动选择。如果选择的是随机选择,则提示需要购买的注数;
如果是手动选择,则让用户首选输入红球数字,然后输入篮球数字。
用户选择或者输入完毕,则对比号码所匹配的奖次,并且
把中奖号码都要显示出来。
中奖规则:
1 等奖是中 6+1,就是全部中了,奖金 500 万元
2 等奖是中 6+0 就是红球全部中了,奖金保底 3000-2000000 元
3 等奖是 5+1 红球中 5 个,加篮球 奖金 3000 元
4 等奖是 5+0 或者 4+1,奖金 200 元
5 等奖是 4+0 或者 3+1,奖金 10 元
6 等奖是 2+1 或者 1+1 或者 0+1,奖金 5 元
中奖号码,要系统自动生成。
3. 业务说明
1. 首先系统要生成中奖号码,而且中奖号码中不能有重复的数字,篮球可以和红球中
某一个数字相同。
2. 当用户输入中奖号码时,需要做判断用户输入的是否为数字,而且一定要在 1-33 或
1-16 之间。
3. 最后根据用户购买的注数,提示所中奖金的总金额,并且提示每注所属的奖项范围。


自定义方法类

 

public class SysRule {

    private static ArrayList<Integer> arr = new ArrayList<Integer>();
    static ArrayList<Integer> ars = new ArrayList<>();

    public static ArrayList<Integer> getArs() {
        return ars;
    }

    public static ArrayList<Integer> getArr() {
        return arr;
    }
    /*
    * 系统规则类
    *
    * */


//    中奖规则:
//    1 等奖是中 6+1,就是全部中了,奖金 500 万元
//    2 等奖是中 6+0 就是红球全部中了,奖金保底 3000-2000000 元
//    3 等奖是 5+1 红球中 5 个,加篮球 奖金 3000 元
//    4 等奖是 5+0 或者 4+1,奖金 200 元
//    5 等奖是 4+0 或者 3+1,奖金 10 元
//    6 等奖是 2+1 或者 1+1 或者 0+1,奖金 5 元
//    中奖号码,要系统自动生成。


    //验证中奖
    public static void winrules(){
        if (ars.size()>7){
            System.out.println("输入数量有误");
            return;
        }
        int redcount = 0;
        int bluecount = 0;
        Object[] objects = ars.toArray();
        Object[] objects1 = arr.toArray();
        for (int i = 0; i < objects1.length - 1&&i<objects.length-1; i++){
            if (objects1[i].equals(objects[i])){
                redcount++;
            }
        }
        if (objects1[objects1.length - 1].equals(objects[objects.length - 1])){
            bluecount++;
        }

        switch (bluecount){
            case 1 :{
                switch (redcount){
                    case 0: {System.out.println("获奖五元");break;}
                    case 1: {System.out.println("获奖五元");break;}
                    case 2: {System.out.println("获奖五元");break;}
                    case 3: {System.out.println("获奖十元");break;}
                    case 4: {System.out.println("获奖二百元");break;}
                    case 5: {System.out.println("获奖三千元");break;}
                    case 6: {System.out.println("恭喜!获奖五百万元");}
                }
                break;
            }
            case 0 :{
                switch (redcount){
                    case 4: {System.out.println("获奖十元");break;}
                    case 5: {System.out.println("获奖两百元");break;}
                    case 6: {System.out.println("恭喜!获奖"+getMoney()+"元");break;}
                    case 1 : {System.out.println("抱歉,没有中奖");break;}
                    case 2 : {System.out.println("抱歉,没有中奖");break;}
                    case 3 : {System.out.println("抱歉,没有中奖");break;}
                    case 0 : {System.out.println("抱歉,没有中奖");}
                }

            }
        }



    }


    //生成中奖号码
    public static void winNumber(){
        Random ran = new Random();
        int count = 0;
        while (true){
            int i1 = (ran.nextInt(32)+1);
            if (arr.contains(i1)){
                continue;
            }else {
                arr.add(i1);
                count++;
            }
            if (count == 6){
                break;
            }
        }


        arr.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.intValue() - o2.intValue();
            }
        });

        //蓝球
        int i = ran.nextInt(15) + 1;
        arr.add(i);

    }
    //查看中奖号码
    public static void CheckNum(){
        Object[] objects = arr.toArray();
        System.out.print("红球是:");
        for (int i = 0; i < objects.length-1; i++){
            System.out.print(objects[i]+" ");
        }
        System.out.println("蓝球是: " + objects[objects.length - 1]);
    }

    public static int getMoney(){
        Random ran = new Random();
        return ran.nextInt(1997000)+3000;
    }

    //自动取号
    public static void autogetNum(){
        Random ran = new Random();
        System.out.print("红球选号中:");
        int count = 0;
        while (true) {
            int i = (ran.nextInt(32) + 1);
            if (ars.contains(i)) {
                continue;
            } else {
                ars.add(i);
                System.out.print(i + "  ");
                count++;
            }
            if (count == 6) {
                break;
            }
        }
        System.out.println();
        System.out.print("蓝球选号中:");
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        int i = ran.nextInt(15) + 1;
        System.out.println(i);
        ars.add(i);

    }

    //手动选号
    public static void getNum(){
        System.out.println("请选择六个不相同的红球");
        Scanner scan = new Scanner(System.in);
        int count = 0;
        while (true){
            int i1 = scan.nextInt();
            if (ars.contains(i1)){
                System.out.println("输入号码重复,请重新选择");
                continue;
            }else {
                ars.add(i1);
                System.out.println("添加成功,号码是:"+i1);
                count++;
            }
            if (count == 6){
                break;
            }
        }

        System.out.println("请选择蓝球");
        while (true) {
            int i = scan.nextInt();
            if (i<1||i>16){
                System.out.println("请选择1-16范围内的数字");
            }else {
                System.out.println("添加成功");
                ars.add(i);
                break;
            }
        }

        System.out.println("您选择的红球号码为:");
        for (Integer in:ars){
            System.out.println(in);
        }
        System.out.println("您选择的蓝球号码为");
        System.out.println(ars.get(6));

    }


}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值