自己写的双色球系统,有兴趣的试试

这个系统写的有点多,按道理直接随机数去重就行了,但是嘛,买彩票怎么能这么随便的呢,你懂的,嘿嘿,可以把随机数改成高次方程带随机数参,还不是很完善,祝你高中大奖!

public class Ball {
public String color;
public int num;
public double chuxianjilv;
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public double getChuxianjilv() {
return chuxianjilv;
}
public void setChuxianjilv(double chuxianjilv) {
this.chuxianjilv = chuxianjilv;
}
}




public class Machie {
public Ball[] redBall = new Ball[33];
public Ball[] blueBall = new Ball[16];
public Machie(){
int i= 0;
for(Ball s : this.redBall){
this.redBall[i++] = new Ball();
}
i=0;
for(Ball s : this.blueBall){
this.blueBall[i++] = new Ball();
}
for(i=0;i<33;i++){
this.redBall[i].color = "红色";
this.redBall[i].num = i+1;
}
for(i=0;i<16;i++){
this.blueBall[i].color = "蓝色";
this.blueBall[i].num = i+1;
}
}
public void run(){
System.out.println("摇奖开始");
//第一次拿奖
int i = 0,n,n1,n2,n3,n4,n5,n6;
double[] a = new double[33];
for(i=0;i < 33;i++){
this.redBall[i].chuxianjilv = Math.random();
a[i] = this.redBall[i].chuxianjilv;
}
n1=max(a);
if(this.redBall[n1].num < 10){
System.out.println("this.redBall[n].color"+"0"+this.redBall[n1].num);
}
else System.out.println("this.redBall[n].color"+this.redBall[n1].num);
//第二次拿奖
for(i=0;i < 33;i++){
if(i == n1)this.redBall[i].chuxianjilv = 0;
else this.redBall[i].chuxianjilv = Math.random();
a[i] = this.redBall[i].chuxianjilv;
}
n2=max(a);
if(this.redBall[n2].num < 10){
System.out.println("this.redBall[n2].color"+"0"+this.redBall[n2].num);
}
else System.out.println("this.redBall[n2].color"+this.redBall[n2].num);
//第三次拿奖
for(i=0;i < 33;i++){
if(i == n1 || i == n2)this.redBall[i].chuxianjilv = 0;
else this.redBall[i].chuxianjilv = Math.random();
a[i] = this.redBall[i].chuxianjilv;
}
n3=max(a);
if(this.redBall[n3].num < 10){
System.out.println("this.redBall[n3].color"+"0"+this.redBall[n3].num);
}
else System.out.println("this.redBall[n3].color"+this.redBall[n3].num);
//第四次
for(i=0;i < 33;i++){
if(i == n1 || i == n2 || i==n3)this.redBall[i].chuxianjilv = 0;
else this.redBall[i].chuxianjilv = Math.random();
a[i] = this.redBall[i].chuxianjilv;
}
n4=max(a);
if(this.redBall[n4].num < 10){
System.out.println("this.redBall[n4].color"+"0"+this.redBall[n4].num);
}
else System.out.println("this.redBall[n4].color"+this.redBall[n4].num);
//第5次
for(i=0;i < 33;i++){
if(i == n1 || i == n2 || i==n3 || i==n4)this.redBall[i].chuxianjilv = 0;
else this.redBall[i].chuxianjilv = Math.random();
a[i] = this.redBall[i].chuxianjilv;
}
n5=max(a);
if(this.redBall[n5].num < 10){
System.out.println("this.redBall[n5].color"+"0"+this.redBall[n5].num);
}
else System.out.println("this.redBall[n5].color"+this.redBall[n5].num);
//第6次
for(i=0;i < 33;i++){
if(i == n1 || i == n2 || i==n3 || i==n4 || i==n5)this.redBall[i].chuxianjilv = 0;
else this.redBall[i].chuxianjilv = Math.random();
a[i] = this.redBall[i].chuxianjilv;
}
n6=max(a);
if(this.redBall[n6].num < 10){
System.out.println("this.redBall[n6].color"+"0"+this.redBall[n6].num);
}
else System.out.println("this.redBall[n6].color"+this.redBall[n6].num);
//蓝色奖
for(i=0;i < 16;i++){
this.blueBall[i].chuxianjilv = Math.random();
a[i] = this.blueBall[i].chuxianjilv;
}
n=max(a);
if(this.blueBall[n].num < 10){
System.out.println("this.blueBall[n].color"+"0"+this.blueBall[n].num);
}
else System.out.println("this.blueBall[n].color"+this.blueBall[n].num);

}
public int max(double[] a){
int i;
double max;
max = a[0];
int j = 0;
int n = 0 ;
for(i = 0;i < a.length;i++){
if(a[i] > max) // 判断最大值
j = i;
max = a[i];
}
return i;
}
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值