java基础项目-抽奖机-模拟双色球-大乐透:
创建了很多的方法逐个编译的,做的很新手 不足之处希望多多交流。谢谢。
需求分析:
欢迎界面
欢迎使用超级幸运抽奖机
选彩种(1.双色球;2.超级大乐透)
正确输入:
请选择彩票编号(1.超级大乐透;2.双色球):
1
错误输入:
请选择彩票编号(1.超级大乐透;2.双色球):
3
很抱歉,暂时没有您选择的彩种,请确认后重新选择!
2
继续错误输入:
请选择彩票编号(1.超级大乐透;2.双色球):
5
很抱歉,暂时没有您选择的彩种,请确认后重新选择!
2
确定选号方式(1.手动选号;2.随机选号)
正确输入:
随机生成号码
请选择手动选号/随机选号(1.手动;2.随机)
2
您随机到的红球分别是:
13 18 20 21 22 28
您随机到的蓝球分别是:
01
手动生成号码
请从1到35中选择5个红球号码:
您选择的第1个号码是:
21
您选择的第2个号码是:
32
您选择的第3个号码是:
12
您选择的第4个号码是:
15
您选择的第5个号码是:
27
升序排列
您选择的红球分别是:
12 15 21 27 32
请从1到12中选择2个蓝球号码:
您选择的第1个号码是:
12
您选择的第2个号码是:
3
升序排列
您选择的蓝球分别是:
03 12
错误输入:
请选择手动选号/随机选号(1.手动;2.随机)
4
您的选择有误,请重新选择:
2
手动选号:
错误输入
您选择的第1个号码是:
12
您选择的第2个号码是:
55
您输入的号码超过了35,请确认后重新输入!
12
您输入的号码重复,请确认后重新输入!
正确输入(即不超过范围且无重复)
您选择的第3个号码是:
34
您选择的第4个号码是:
23
提示本彩种的选号个数及选号范围
选号不合要求提供容错处理
请从1到35中选择5个红球号码:
请从1到12中选择2个蓝球号码:
提示输入选择是第几个号码
如:
您选择的第4个号码是:
输入购买数量
请输入购买注数:
余额足够
您购买的注数为:5
余额不足
您下注所需金额为:200元,您的账户余额为:90元
您的余额已不足!
您可以选择如下操作:
1.减小购买数量
2.为您的账户充值
3.退出程序
减小购买数量
请输入您要购买的数量:
10
您购买的注数为:10
为您的账户充值
请输入充值金额:
1000
您购买的注数为:100
退出程序
退出程序
展示客户选择的号码
您随机到的红球分别是:
11 12 22 23 29
您随机到的蓝球分别是:
04 07
展示开奖号码
开出的红球分别是:
10 12 19 20 29
开出的蓝球分别是:
01 08
对照号码
您选择的红球分别是:11 12 22 23 29 您选择的蓝球分别是:04 07
而开出的红球分别是:10 12 19 20 29 而开出的蓝球分别是:01 08
展示客户中奖号码
您的红球中奖号码分别是: 12 29 红球中奖2个。
展示客户的中奖情况
很遗憾,您没有中奖。
是否继续
正确输入
继续/退出(继续:Y;退出:N)
y
请选择彩票编号(1.超级大乐透;2.双色球):
错误输入
继续/退出(继续:Y;退出:N)
s
您的选择有误,请确认后重新选择!
package day1030;
import java.util.Random;
import java.util.Scanner;
public class 幸运抽奖机 {
/**
* 幸运抽奖机文档.doc
*/
public static void main(String[] args) {
//创建一个welcome()的方法
welcome();
}
static int arr[] = new int[7];
static Scanner scanner = new Scanner(System.in);
static int zhu;
static int money = 50;
static int[] dlt = new int[7];
static int[] ssq = new int[7];
public static void welcome() {
System.out.println("欢迎使用超级幸运抽奖机选彩种\n(1.超级大乐透;2.双色球)");
int choose = scanner.nextInt();
switch (choose) {
case 1:
daletou();
break;
case 2:
shuangseqiu();
break;
default:
System.out.println("不对 重新输入");
welcome();
break;
}
}
//双色球的方法
public static void shuangseqiu() {
System.out.println("确定选号方式(1.手动选号;2.随机选号)");
int choose = scanner.nextInt();
switch (choose) {
case 1:
ssqshoudong();
goumai();
ssqshow();
break;
case 2:
ssqsuiji();
goumai();
ssqshow();
break;
default:
System.out.println("重试");
shuangseqiu();
break;
}
}
public static void ssqshow() {
System.out.println("您选择的红球分别是:");
for (int i = 0; i < arr.length - 1; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
System.out.println("您选择的蓝球是:");
System.out.print(arr[6]);
ssqkaijiang();
}
public static void ssqkaijiang() {
for (int i = 0; i < ssq.length - 1; i++) {
int random = new Random().nextInt(33) + 1;
ssq[i] = random;
for (int j = 0; j < i; j++) {
if (ssq[i]==ssq[j]) {
i--;
break;
}
}
}
for (int i = 6; i < ssq.length; i++) {
int random = new Random().nextInt(12) + 1;
ssq[i] = random;
for (int j = 0; j < i; j++) {
if (ssq[i]==ssq[j]) {
i--;
break;
}
}
}
for (int i = 0; i < ssq.length - 2; i++) {
for (int j = 0; j < ssq.length - 2; j++) {
if (ssq[j] > ssq[j + 1]) {
int temp = ssq[j];
ssq[j] = ssq[j + 1];
ssq[j + 1] = temp;
}
}
}
System.out.println();
System.out.println("开奖号码,红球分别是:");
for (int i = 0; i < ssq.length - 1; i++) {
System.out.print(ssq[i] + " ");
}
System.out.println();
System.out.println("开奖号码,蓝球分别是:");
System.out.print(ssq[6] + " ");
int redcount = 0;
System.out.println("\n您的红球中奖号码是:");
for (int i = 0; i < ssq.length - 1; i++) {
for (int j = 0; j < arr.length - 1; j++) {
if (ssq[i] == arr[j]) {
System.out.print(ssq[i]+" ");
redcount++;
}
}
}
System.out.println("\n红球中奖" + redcount + "个");
int bluecount = 0;
System.out.println("\n您的蓝球中奖号码是:");
if (dlt[6] == arr[6]) {
System.out.print(dlt[6]);
bluecount++;
}
System.out.println("\n蓝球中奖" + bluecount + "个");
if ((bluecount == 1 && redcount == 0)
|| (bluecount == 1 && redcount == 1)
|| (bluecount == 1 && redcount == 2)) {
money = money + (5 * zhu);
System.out.println("六等奖,奖金:" + (5 * zhu) + "元");
System.out.println("余额为" + money + "元");
} else if ((bluecount == 1 && redcount == 3)
|| (bluecount == 0 && redcount == 4)) {
money = money + (10 * zhu);
System.out.println("五等奖,奖金:" + (10 * zhu) + "元");
System.out.println("余额为" + money + "元");
} else if ((bluecount == 0 && redcount == 5)
|| (bluecount == 1 && redcount == 4)) {
money = money + (200 * zhu);
System.out.println("四等奖,奖金:" + (200 * zhu) + "元");
System.out.println("余额为" + money + "元");
} else if ((bluecount == 1 && redcount == 5)) {
money = money + (3000 * zhu);
System.out.println("三等奖,奖金:" + (3000 * zhu) + "元");
System.out.println("余额为" + money + "元");
} else if ((bluecount == 0 && redcount == 6)) {
money = money + (200000 * zhu);
System.out.println("二等奖,奖金:" + (200000 * zhu) + "元");
System.out.println("余额为" + money + "元");
} else if ((bluecount == 1 && redcount == 6)) {
money = money + (5000000 * zhu);
System.out.println("一等奖!!!!!!奖金:" + (5000000 * zhu) + "元");
System.out.println("余额为" + money + "元");
} else {
System.out.println("很遗憾 你没有中奖");
System.out.println("余额为" + money + "元");
boolean flag = true;
do {
System.out.println("是否继续 y/n");
String jx = scanner.next();
if (jx.equalsIgnoreCase("y")) {
flag = false;
welcome();
} else if (jx.equalsIgnoreCase("n")) {
System.exit(0);
} else {
System.out.println("输入有误,请重新输入");
}
} while (flag);
}
}
public static void ssqsuiji() {
for (int i = 0; i < arr.length - 1; i++) {
int random = new Random().nextInt(33) + 1;
arr[i] = random;
for (int j = 0; j < i; j++) {
if (arr[i]==arr[j]) {
i--;
break;
}
}
}
for (int i = 6; i < arr.length; i++) {
int random = new Random().nextInt(16) + 1;
arr[i] = random;
for (int j = 0; j < i; j++) {
if (arr[i]==arr[j]) {
i--;
break;
}
}
}
for (int i = 0; i < arr.length - 2; i++) {
for (int j = 0; j < arr.length - 2; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println();
System.out.println("您随机的红球分别是:");
for (int i = 0; i < arr.length - 1; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
System.out.println("您随机的蓝球是:");
System.out.print(arr[6]);
}
public static void ssqshoudong() {
System.out.println("请从1到33中选择6个红球号码:");
for (int i = 0; i < arr.length - 1; i++) {
System.out.println("您选择的第" + (i + 1) + "个号码是:");
int number = scanner.nextInt();
while (number < 1 || number > 33) {
System.out.println("你输入的数字不在范围内 重新输");
number = scanner.nextInt();
}
arr[i] = number;
for (int j = 0; j < i; j++) {
if (arr[i]==arr[j]) {
System.out.println("重复咯, 重新输");
i--;
break;
}
}
}
for (int i = 0; i < arr.length - 2; i++) {
for (int j = 0; j < arr.length - 2; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println("您选择的红球分别是:");
for (int i = 0; i < arr.length - 1; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
for (int i = 6; i < arr.length; i++) {
System.out.println("您选择的蓝球是:");
int number = scanner.nextInt();
while (number < 1 || number > 12) {
System.out.println("你输入的数字不在范围内 重新输");
number = scanner.nextInt();
}
arr[i] = number;
for (int j = 0; j < i; j++) {
if (arr[i]==arr[j]) {
System.out.println("重复咯, 重新输");
i--;
break;
}
}
}
System.out.println("您选择的蓝球是:");
System.out.print(arr[6]);
}
public static void daletou() {
System.out.println("确定选号方式(1.手动选号;2.随机选号)");
int choose = scanner.nextInt();
switch (choose) {
case 1:
shoudong();
goumai();
show();
break;
case 2:
suiji();
goumai();
show();
break;
default:
System.out.println("重试");
daletou();
break;
}
}
public static void goumai() {
boolean flag = true;
do {
System.out.println("\n请输入购买注数:");
zhu = scanner.nextInt();
if (zhu * 10 > money) {
System.out.println("您下注所需金额为:" + (zhu * 10) + "元,您的账户余额为"
+ money + "元");
System.out
.println("您的余额已不足!您可以选择如下操作:\n1.减小购买数量\n2.为您的账户充值\n3.退出程序");
int choose = scanner.nextInt();
switch (choose) {
case 1:
break;
case 2:
System.out.println("请输入充值金额:");
int chongzhi = scanner.nextInt();
money = money + chongzhi;
break;
case 3:
System.exit(0);
break;
default:
break;
}
} else if (zhu * 10 <= money) {
money = money - zhu * 10;
System.out.println("购买成功,购买注数为" + zhu + "注");
flag = false;
} else {
System.out.println("填写有误,重新购买");
goumai();
}
} while (flag);
}
public static void kaijiang() {
for (int i = 0; i < dlt.length - 2; i++) {
int random = new Random().nextInt(35) + 1;
dlt[i] = random;
for (int j = 0; j < i; j++) {
if (dlt[i]==dlt[j]) {
i--;
break;
}
}
}
for (int i = 5; i < dlt.length; i++) {
int random = new Random().nextInt(12) + 1;
dlt[i] = random;
for (int j = 0; j < i; j++) {
if (dlt[i]==dlt[j]) {
i--;
break;
}
}
}
for (int i = 0; i < dlt.length - 3; i++) {
for (int j = 0; j < dlt.length - 3; j++) {
if (dlt[j] > dlt[j + 1]) {
int temp = dlt[j];
dlt[j] = dlt[j + 1];
dlt[j + 1] = temp;
}
}
}
System.out.println();
System.out.println("开奖号码,红球分别是:");
for (int i = 0; i < dlt.length - 2; i++) {
System.out.print(dlt[i] + " ");
}
for (int i = 5; i < dlt.length - 1; i++) {
for (int j = 5; j < dlt.length - 1; j++) {
if (dlt[j] > dlt[j + 1]) {
int temp = dlt[j];
dlt[j] = dlt[j + 1];
dlt[j + 1] = temp;
}
}
}
System.out.println();
System.out.println("开奖号码,蓝球分别是:");
for (int i = 5; i < dlt.length; i++) {
System.out.print(dlt[i
] + " ");
}
int redcount = 0;
System.out.println("\n您的红球中奖号码是:");
for (int i = 0; i < dlt.length - 2; i++) {
for (int j = 0; j < arr.length - 2; j++) {
if (dlt[i] == arr[j]) {
System.out.print(dlt[i]+" ");
redcount++;
}
}
}
System.out.println("\n红球中奖" + redcount + "个");
int bluecount = 0;
System.out.println("您的蓝球中奖号码是:");
for (int i = 5; i < dlt.length; i++) {
for (int j = 5; j < arr.length; j++) {
if (dlt[i] == arr[j]) {
System.out.print(dlt[i]+" ");
bluecount++;
}
}
}
System.out.println("\n蓝球中奖" + bluecount + "个");
if ((bluecount == 2 && redcount == 0)
|| (bluecount == 2 && redcount == 1)
|| (bluecount == 1 && redcount == 2)
|| (bluecount == 0 && redcount == 3)) {
money = money + (5 * zhu);
System.out.println("六等奖,奖金:" + (5 * zhu) + "元");
System.out.println("余额为" + money + "元");
} else if ((bluecount == 2 && redcount == 2)
|| (bluecount == 1 && redcount == 3)
|| (bluecount == 0 && redcount == 4)) {
money = money + (10 * zhu);
System.out.println("五等奖,奖金:" + (10 * zhu) + "元");
System.out.println("余额为" + money + "元");
} else if ((bluecount == 2 && redcount == 3)
|| (bluecount == 1 && redcount == 4)) {
money = money + (200 * zhu);
System.out.println("四等奖,奖金:" + (200 * zhu) + "元");
System.out.println("余额为" + money + "元");
} else if ((bluecount == 2 && redcount == 4)
|| (bluecount == 0 && redcount == 5)) {
money = money + (3000 * zhu);
System.out.println("三等奖,奖金:" + (3000 * zhu) + "元");
System.out.println("余额为" + money + "元");
} else if ((bluecount == 1 && redcount == 5)) {
money = money + (200000 * zhu);
System.out.println("二等奖,奖金:" + (200000 * zhu) + "元");
System.out.println("余额为" + money + "元");
} else if ((bluecount == 2 && redcount == 5)) {
money = money + (5000000 * zhu);
System.out.println("一等奖!!!!!!奖金:" + (5000000 * zhu) + "元");
System.out.println("余额为" + money + "元");
} else {
System.out.println("很遗憾 你没有中奖");
System.out.println("余额为" + money + "元");
boolean flag = true;
do {
System.out.println("是否继续 y/n");
String jx = scanner.next();
if (jx.equalsIgnoreCase("y")) {
flag = false;
welcome();
} else if (jx.equalsIgnoreCase("n")) {
System.exit(0);
} else {
System.out.println("输入有误,请重新输入");
}
} while (flag);
}
}
public static void show() {
System.out.println("您选择的红球分别是:");
for (int i = 0; i < arr.length - 2; i++) {
System.out.print(arr[i] + " ");
}
for (int i = 5; i < arr.length - 1; i++) {
for (int j = 5; j < arr.length - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println();
System.out.println("您选择的蓝球分别是:");
for (int i = 5; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
kaijiang();
}
public static void suiji() {
for (int i = 0; i < arr.length - 2; i++) {
int random = new Random().nextInt(35) + 1;
arr[i] = random;
for (int j = 0; j < i; j++) {
if (arr[i]==arr[j]) {
i--;
break;
}
}
}
for (int i = 5; i < arr.length; i++) {
int random = new Random().nextInt(12) + 1;
arr[i] = random;
for (int j = 0; j < i; j++) {
if (arr[i]==arr[j]) {
i--;
break;
}
}
}
for (int i = 0; i < arr.length - 3; i++) {
for (int j = 0; j < arr.length - 3; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println();
System.out.println("您随机的红球分别是:");
for (int i = 0; i < arr.length - 2; i++) {
System.out.print(arr[i] + " ");
}
for (int i = 5; i < arr.length - 1; i++) {
for (int j = 5; j < arr.length - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println();
System.out.println("您随机的蓝球分别是:");
for (int i = 5; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
public static void shoudong() {
System.out.println("请从1到35中选择5个红球号码:");
for (int i = 0; i < arr.length - 2; i++) {
System.out.println("您选择的第" + (i + 1) + "个号码是:");
int number = scanner.nextInt();
while (number < 1 || number > 35) {
System.out.println("你输入的数字不在范围内 重新输");
number = scanner.nextInt();
}
arr[i] = number;
for (int j = 0; j < i; j++) {
if (arr[i]==arr[j]) {
System.out.println("重复咯, 重新输");
i--;
break;
}
}
}
for (int i = 0; i < arr.length - 3; i++) {
for (int j = 0; j < arr.length - 3; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println("您选择的红球分别是:");
for (int i = 0; i < arr.length - 2; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
for (int i = 5; i < arr.length; i++) {
System.out.println("您选择的第" + (i - 4) + "个蓝球是:");
int number = scanner.nextInt();
while (number < 1 || number > 12) {
System.out.println("你输入的数字不在范围内 重新输");
number = scanner.nextInt();
}
arr[i] = number;
for (int j = 5; j < i; j++) {
if (arr[i]==arr[j]) {
System.out.println("重复咯,重新输!");
i--;
break;
}
}
}
for (int i = 5; i < arr.length - 1; i++) {
for (int j = 5; j < arr.length - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println("您选择的蓝球分别是:");
for (int i = 5; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}