项目:【双色球彩票】系统

一个小项目:纯代码的一个项目:【双色球彩票】系统,不太完善,仅供参考
package com.ayxy;

import java.util.Random;
import java.util.Scanner;
public class shuangseqiu {

public static void main(String[] args) {
    /* 页面介绍
     *  自己写一个 双色球 彩票 系统
     * 1.注册
     * 2.登陆
     * 3.机选
     * 4.自选
     * 5.查看
     * 6.开奖
     * 7.退出系统
     * */
    //1.数组存储账号、密码  空为 null
    // 100 是自定义的 100 个人注册  2 是 要输入两次密码
        String[][] userArr = new String[100][2];
    /*
     * [["student0","111"]
     * ["student1","111"]]
     */
    //2.二维数组 存储彩票的结果  空为0
    // 你可以机选 100 注 每一注 7 个数字
        int[][] dataArr = new int [100][7];
    /*
     * [[1,5,12,14,22,30,11][10,5,2,4,32,3,4]]
     */
    //3.定义输入的对象 Scanner
        Scanner scanner = new Scanner(System.in);
    //4.定义一个布尔类型变量 用于循环系统  boolean  是一个死循环 一直循环 为false 退出系统
        boolean isRun = true;
    //5.定义用于记录登陆状态的变量   初始时没有登陆  为True 登陆
        boolean isLogin = false;
    //进入彩票系统
        while (isRun) {
            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("7.退出系统");
            System.out.println("输入你的选择:");
    //获取你输入的数字  利用循环 1 进入注册  2 登陆  ...          
        int result = scanner.nextInt();
    //满足条件一直循环
        switch (result) {
            case 1:
            //注册
            //1.用户名不能重复
            //2.两次输入密码一致
            //3.存储用户信息:账号,密码
            //存储 用户名 状态
            boolean hasName = true;
            //存储用户名  默认为空
            String name = "";
            //控制台输入用户名
            System.out.println("请输入用户名:");
            while (hasName) {
            name = scanner.next();
            //遍历,判断
            for (int i = 0; i < userArr.length; i++) {
            //名字如果重复,就不得注册
            //如果 你的 用户名不等于空 而且 跟你输入的name 一样的  话  就是说明注册过了
            if (userArr[i][0] != null && userArr[i][0].equals(name)) {
            System.out.println("用户已存在,请重新输入:");
            hasName = true;
            break;
            }else {
            hasName = false;
            }
        }
    }
            //判断密码
            //定义变量 判断密码是否一致
            boolean isEqual = true;
            String pwd = null;  
            while(isEqual){
                System.out.println("请输入密码:");
                pwd = scanner.next();
                System.out.println("请再次输入密码:");
                String repeat = scanner.next();
                //判断密码
                if(pwd.equals(repeat)){
                //两次一致
                isEqual = false;
                }else {
                System.out.println("两次输入的密码不一致!");
                isEqual  = true;
                }
            }
                //添加用户信息
                for(int i = 0; i < userArr.length; i++){
                    if(userArr[i][0] == null){
                    //添加信息
                    userArr[i][0] = name;
                    userArr[i][1] = pwd;
                    System.out.println("注册成功!棒棒哒!");
                    break;
                }
            }       
                    break;  
                case 2:
                    //登陆
                    if(isLogin){
                 System.out.println("已登录!");
                    break;
                    }
                    // 未登录!
                    System.out.println("请输入用户名:");
                    String name1 = scanner.next();
                    System.out.println("请输入密码:");
                    String pwd1 = scanner.next();
                    //遍历判断!!!
                    for(int i = 0; i < userArr.length; i++){
                        if(userArr[i][0] != null && userArr[i][0].equals(name1) && userArr[i][1].equals(pwd1)){
                            System.out.println("登陆成功!");
                            isLogin = true;
                            break;  
                        }else{
                            isLogin = false;
                        }
                    }                     
                    if(isLogin == false){
                        System.out.println("登陆失败!");
                    }            
                    break;
                 case 3:
                //机选
                     if(isLogin == false){
                        System.out.println("请登陆!");
                        break;
                     }
                     //执行此处!说明已登录!开始机选!
                     System.out.print("请输入机选的注数:");
                     int count = scanner.nextInt();
                     Random random = new Random();
                     //外层控制行数 也就是彩票的注数
                     for(int i = 0; i < count; i++){
                         int num[] = new int[7];                             
                         //内层开始随机前6个红球
                         for(int j = 0; j < 6; j++){
                             int temp = random.nextInt(33) + 1;
                             //定义变量存储此球是否重复
                             boolean isExist = false;
                             //此循环用来遍历数组!!!!
                             for(int k = 0; k < 6; k++){
                                 if(temp == num[k]){
                                     isExist = true;
                                     j--;
                                     break;
                                 }
                             }                               
                             if(isExist == false){
                                 //数字不存在 就添加
                                 num[j] = temp;
                             } 
                         }
                         //给红球升序排序
                         for(int m = 0; m < 6 - 1; m++){
                             for(int n = 0; n < 6 - 1 - m; n++){
                                 if(num[n] > num[n+1]){
                                     int t = num[n];
                                     num[n] = num[n + 1];
                                     num[n + 1] = t;
                                 }
                             }
                         }
                         //添加最后的蓝色球
                         num[6] = random.nextInt(16) + 1;
                         //--------------------------------------
                         //查看结果
                         System.out.println("机选号码为:");
                         for(int m = 0; m < 7; m++){
                             if(num[m] < 10){
                                 System.out.print("0" + num[m] + " ");
                             }else{
                                 System.out.print( num[m] + " ");        
                             }
                         }
                         System.out.println();
                         //将结果放入二位数组中!!!!
                         for(int j = 0; j < dataArr.length; j++){
                             if(dataArr[j][0] == 0) {
                                for(int k = 0; k < 7; k++){
                                    dataArr[j][k] = num[k];
                                }
                                 break;
                             }                       
                         }                           
                     }
                    break;
                 case 4:
                  //自选开始
                     System.out.println("请输入自选注数");
                     int count1 = scanner.nextInt();
                     for (int i = 0; i < count1; i++) {
                         int[] array = new int[7];
                        int s = i + 1;
                        System.out.println("请输入第" + s + "注");
                        for (int j = 0; j < 7; j++) {
                            int temp = scanner.nextInt();
                            array[j] = temp;
                        }
                        //输入一注之后,打印出来
                        for (int k = 0; k < 7; k++) {
                            System.out.println(array[k] + " ");
                        }
                        System.out.println();
                    }
                    break;
                 case 5:
                 //查看
                     if(isLogin == false){
                            System.out.println("请登陆!");
                            break;
                         }
                     //输出二位数组!!!
                     for(int i = 0; i < dataArr.length; i++){
                         if(dataArr[i][0] == 0){
                             break;
                         }

                             //循环其中的一维数组
                             for(int j = 0; j < 7; j++){
                                 if(dataArr[i][j] < 10){
                                     System.out.print("0" + dataArr[i][j] + " ");
                                 }else{
                                     System.out.print( dataArr[i][j] + " ");

                                 }
                             }   
                             System.out.println();
                         }
                    break;
                 case 6:
                //开奖
                     Random random1 = new Random();
                //前6个数字 1--33; 最后一个是1--16
                    int[] test1 = new int[7];
                    //前6个数字
                    for(int i = 0; i < 6; i++){
                        boolean isOK = true;
                        int temp = random1.nextInt(33) + 1; 
                        for(int j = 0; j < 6; j++){
                            if(temp == test1[j]){
                                i--;
                                isOK = false; 
                                break;
                                }                                   
                            }
                            if(isOK){
                                test1[i] = temp;
                            }
                            System.out.print(temp + "\t");                              
                        }
                        //随机蓝色的球
                        test1[6] = random1.nextInt(16) + 1;

                        System.out.println();
                        for(int i = 0; i < 7; i++){
                            System.out.print(test1[i] + "\t");
                        }
                    break;
                 case 7:
               //退出登陆
                     isRun = false;
                    break;                      
                default:
                    break;
                }                   
            }
}

}
验证结果:
欢迎进入【双色球彩票】系统
1.注册
2.登陆
3.机选
4.自选
5.查看
6.开奖
7.退出系统
输入你的选择:
1
请输入用户名:
11
请输入密码:
123
请再次输入密码:
123
注册成功!棒棒哒!
欢迎进入【双色球彩票】系统
1.注册
2.登陆
3.机选
4.自选
5.查看
6.开奖
7.退出系统
输入你的选择:
2
请输入用户名:
11
请输入密码:
123
登陆成功!
欢迎进入【双色球彩票】系统
1.注册
2.登陆
3.机选
4.自选
5.查看
6.开奖
7.退出系统
输入你的选择:
3
请输入机选的注数:2
机选号码为:
06 12 14 19 24 29 01
机选号码为:
01 07 08 11 22 23 14
欢迎进入【双色球彩票】系统
1.注册
2.登陆
3.机选
4.自选
5.查看
6.开奖
7.退出系统
输入你的选择:
4
请输入自选注数
2
请输入第1注
1
2
3
4
5
6
7
1
2
3
4
5
6
7

请输入第2注
1
2
3
4
5
6
7
1
2
3
4
5
6
7

欢迎进入【双色球彩票】系统
1.注册
2.登陆
3.机选
4.自选
5.查看
6.开奖
7.退出系统
输入你的选择:
5
06 12 14 19 24 29 01
01 07 08 11 22 23 14
欢迎进入【双色球彩票】系统
1.注册
2.登陆
3.机选
4.自选
5.查看
6.开奖
7.退出系统
输入你的选择:
6
33 17 18 19 7 21
33 17 18 19 7 21 6 欢迎进入【双色球彩票】系统
1.注册
2.登陆
3.机选
4.自选
5.查看
6.开奖
7.退出系统
输入你的选择:
7

猜你喜欢

转载自blog.csdn.net/qq_40477146/article/details/80031435