目录
双色球彩票管理系统
1.双色球玩法说明
2.系统功能介绍
3.主要信息及代码展示
注册一个账户,进入系统可实现之后的登录、机选、自选等功能
登录账号方便之后的操作
随机生成双色球彩票<可选择注数>
可手动输入要选择的号码
查看已经获取的彩票信息
随机出一注彩票作为中奖的彩票
退出系统
package test;
import java.util.Random;
import java.util.Scanner;
public class LotterySystem {
public static void main(String[] args) {
//1.定义二维数组 存储用户信息 账号和密码
String[][] users = new String[100][2];
//2.定义二维数组 存储彩票
int[][] numbers = new int[5][7];
/*
{
{4,12,14,17,22,25,6},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0}
}
*/
//3.记录是否已经登录成功
Boolean isLogin = false;
//4.定义变量,是while进入死循环
Boolean isLoop = true;
while(isLoop){
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("请选择:");
Scanner scanner = new Scanner(System.in);
int choose = scanner.nextInt();
//判断并且执行
switch (choose) {
case 1:
//注册:1.用户名不能重复 2.两次输入密码一致
boolean hasName = true;
String name = null;
while(hasName){
System.out.println("请输入用户名");
name = scanner.next();
//遍历数组 查看用户名是否存在
for(int i = 0; i < users.length; i++){
if(users[i][0] != null && users[i][0].equals(name)){
//用户名已经存储 equals判断字符串是否相等,相等则为true
hasName = true;
System.out.println("用户名已存在!");
break;
}else{
hasName = false;
}
}
}
//------------------------------
boolean isEqual = true;
String pwd = null;
while(isEqual){
System.out.println("请输入密码");
pwd = scanner.next();
System.out.println("请再次输入密码");
String pwd1 = scanner.next();
//判断两次密码是否一致
if(pwd.equals(pwd1)){
isEqual = false;//密码一致 结束循环
}else {
isEqual = true;
System.out.println("两次密码输入不一致!");
}
}
//------------------------------------------
//把用户信息存储到数组中
for(int i = 0; i < 100; i++){
if(users[i][0] == null){
users[i][0] = name;
users[i][1] = pwd;
System.out.println("注册成功!棒棒哒!");
break;
}
}
break;
case 2:
//先判断是否已经登录
if(isLogin) {
System.out.println("已登录!");
break;//其功能直接跳出此case
}
//登录
System.out.println("请输入账号:");
String username = scanner.next();
System.out.println("请输入密码:");
String password = scanner.next();
for(int i = 0; i < users.length; i++){
if(users[i][0] != null && users[i][0].equals(username) && users[i][1].equals(password)){
//此行数据不为空且账号一致 密码一致
isLogin = true;
System.out.println("恭喜!登录成功!");
break;
}
}
if(isLogin == false){
System.out.println("登录失败!");
}
break;
case 3:
if(isLogin == false){
System.out.println("请先进行登录!");
break;
}
//机选是可以多注!!
System.out.println("请输入要机选的注数!");
int count = scanner.nextInt();
for(int k = 0; k < count; k++){
int[] array = new int[7];
Random random = new Random();
int temp = 0;
for(int i = 0; i < 6; i++){
Boolean isExit = false;
temp = random.nextInt(33) + 1;
//遍历数组 查看元素值是否重复
for(int j = 0; j < i; j++){
if(temp == array[j]){
isExit = true;
break;
}
}
//判断temp是否已经存在
if(isExit){
i--;//此次循环无效
}else{
array[i] = temp;
}
}
array[6] = random.nextInt(16) + 1;
//-----------------------------------
for(int i = 0; i < 5; i++){
if(numbers[i][0] == 0){
for(int j = 0; j < 7; j++){
numbers[i][j] = array[j];
}
break;
}
}
}
break;
case 4:
//自选
System.out.println("请输入要自选的注数:");
int count1 = scanner.nextInt();
for(int k = 0; k < count1; k++){
int[] numArray = new int[7];
int temp = 0;
System.out.println("请输入选择的号码!");
for(int i = 0; i < 7; i++){
boolean isExit = false;
temp = scanner.nextInt();
//前6个数字的取值范围1-33 下标 0--5
if(i < 6){
//先判断值范围
if(temp >= 1 && temp <= 33){
//查询是否重复
for(int j = 0; j < 6; j++){
if(temp == numArray[j]){
isExit = true;
}
}
//判断元素是否出现过
if(isExit){
System.out.println("此元素已经出现过,请重新输入!");
i--;
}else {
numArray[i] = temp;
}
}else {
System.out.println("请输入1-33范围的值!");
i--;
}
}else {
//蓝色的球
if(temp >= 1 && temp <= 16){
numArray[i] = temp;
}else {
i--;
System.out.println("蓝色球的取值范围是1-16,请重新输入!");
}
}
}
for(int i = 0; i < 5; i++){
if(numbers[i][0] == 0){
for(int j = 0; j < 7; j++){
numbers[i][j] = numArray[j];
}
break;
}
}
}
break;
case 5:
if(isLogin == false){
System.out.println("请先进行登录!");
break;
}
for(int i = 0; i < 5; i++){
if(numbers[i][0] != 0){
for(int j = 0; j < 7; j++){
System.out.print(numbers[i][j] + " ");
}
System.out.println();
}
}
break;
case 6:
if(isLogin == false){
System.out.println("请先进行登录!");
break;
}
int[] array = new int[7];
Random random = new Random();
int temp = 0;
for(int i = 0; i < 6; i++){
Boolean isExit = false;
temp = random.nextInt(33) + 1;
//遍历数组 查看元素值是否重复
for(int j = 0; j < i; j++){
if(temp == array[j]){
isExit = true;
break;
}
}
//判断temp是否已经存在
if(isExit){
i--;//此次循环无效
}else{
array[i] = temp;
}
}
array[6] = random.nextInt(16) + 1;
System.out.println("最终开奖的结果为:");
for(int i = 0; i < 7; i++){
System.out.print(array[i] + " ");
}
System.out.println();
break;
case 7:
isLoop = false;
break;
default:
break;
}
}
for(int i = 0; i < users.length; i++){
if(users[i][0] != null){
System.out.println(users[i][0] + " " + users[i][1]);
}
}
}
}