/**
* 模拟双色球篮球33选6 红球16选1;
* 客户输入和随机生成的结果比较
* 1.客户输入双色球
* a.输入重复 b.(输入数字不对)
* 2.生成随机球
* a.篮球(1个) b.红球(6个不重复)
* 3. 进行比较,返回一个中奖结果
* a.中奖(中几等奖) b.不中奖(再接再厉)
* @author Administrator
* 4.公布中奖号码
*/
import java.util.*;
public class doubleballDemo01 {
public static void main(String[] args) {
DoubleBallpay p = new DoubleBallpay();
}
}
class DoubleBallpay {
DoubleBallpay() {
String m="n";
// 客户输入
while(m.equals("n")){
System.out.println("您好,欢迎使用双色球,祝君好运!");
System.out.println("*************************************");
System.out.println(" ");
System.out.println("请从1到33中选择6个不相等的红球");
System.out.println("***************");
String[] redball = { "0", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14",
"15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31",
"32", "33" };
String[] blueball = { "0", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14",
"15", "16" };
String[] SystemRedBall = new String[6];// 存6个客户输入的红球
Scanner input = new Scanner(System.in);
int index = 0;
for (int i = 0; i < 6; i++)
{
while (true)
{
try
{
System.out.print("请输入第" + (i + 1) + "个红球:");
index = input.nextInt();
if (index > 33 || index < 0)
{
System.out.println("输入有误,请输入1到33中的红球号");
continue;
}
if (redball[index].equals("0"))
{
System.out.println("输入重复,请重新输入");
continue;
}
}
catch(Exception e)
{
System.out.println("输入重复,请重新输入");
break;
}
SystemRedBall[i] = redball[index];
redball[index] = "0";
break;
}
}
Arrays.sort(SystemRedBall);
System.out.print("红球已选完");
System.out.println("");
System.out.print("请选择一个蓝球:");
int blue = 0;
while (true) {
while (true) {
int blue1 = input.nextInt();
if (blue1 > 16 || blue1 < 0) {
System.out.print("输入有误,请重新输入蓝球:");
continue;
}
blue = blue1;
break;
}
break;
}
System.out.print("蓝球已选完:");
System.out.println();
System.out.println("你选的号码为");
System.out.print("红球:");
for (int i = 0; i < SystemRedBall.length; i++) {
System.out.print(SystemRedBall[i] + " ");
}
System.out.println();
System.out.print("蓝球:");
System.out.print(blueball[blue]);
System.out.println();
/*
* 产生随机球 a.不重复的6个球 b.一个蓝球
*
*
*/
String[] redball1 = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32",
"33" };
String[] blueball1 = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15",
"16" };
String[] RandomredBall = new String[6];// 存随机生成的红球
Random r = new Random();
int index1 = 0;
int length = 0;
// TODO Auto-generated method stub
for (int i = 0; i < 6; i++) {
while (true) {
index1 = r.nextInt(33);
if (redball1[index1].equals("a")) {
continue;
}
RandomredBall[length++] = redball1[index1];
redball1[index1] = "a";
break;
}
}
int indexblue = r.nextInt(16);
String RandomBlue = blueball1[indexblue];
// 3. 进行比较,返回一个中奖结果
// 红球中的个数
int sumred = 0; // 红球中奖数
StringBuffer buf = new StringBuffer();
for (int i = 0; i < SystemRedBall.length; i++) {
for (int j = 0; j < RandomredBall.length; j++) {
if (RandomredBall[j].equals(SystemRedBall[i])) {
sumred++;
buf.append(RandomredBall[j] + " ");
}
}
}
// 蓝球中否
int sumblue = blueball[blue].equals(RandomBlue) ? 1 : 0;
// 判断结果
if (sumred == 6 && sumblue == 1) {
System.out.println("恭喜你,中了一等奖,500万!");
System.out.println("你已成功逆袭高富帅!");
} else if (sumred == 6) {
System.out.println("恭喜你,中了二等奖 100万!");
System.out.println("不错,可以买一辆宝马了!");
} else if (sumred == 5 && sumblue == 1) {
System.out.println("恭喜你,中了三等奖 3000!");
System.out.println("不错,可以给女票买礼物了!");
} else if (sumred == 5) {
System.out.println("恭喜你,中了四等奖 200元!");
System.out.println("不错,可以吃顿好的了!");
} else if (sumred == 4 && sumblue == 1) {
System.out.println("恭喜你,中了四等奖 200元!");
System.out.println("不错,可以吃顿好的了!");
}
else if (sumred == 4) {
System.out.println("恭喜你,中了五等奖 10元!");
System.out.println("不错,买个包子吃吃!");
} else if (sumred == 3 && sumblue == 1) {
System.out.println("恭喜你,中了五等奖 10元!");
System.out.println("不错,买个包子吃吃!");
} else if (sumblue == 1) {
System.out.println("恭喜你,中了六等奖 5元!");
System.out.println("不错,买个冰棍吃吃!");
} else {
System.out.println("你未中奖,请再接再厉!");
}
System.out.println("本期开奖结果为");
System.out.print("红球: ");
Arrays.sort(RandomredBall);
for (int i = 0; i < RandomredBall.length; i++) {
System.out.print(RandomredBall[i] + " ");
}
System.out.println();
System.out.print("蓝球:");
System.out.print(RandomBlue);
System.out.println();
System.out.println("所中红球个数为:" + sumred);
System.out.println("红球为:" + buf);
System.out.println("是否退出系统y/n");
m =input.next();
}
}
}
|
|