导航:首页 > 编程语言 > java大转盘根据中奖概率中奖

java大转盘根据中奖概率中奖

发布时间:2023-03-15 18:04:55

『壹』 做一个java的抽奖系统

用随机的办法 来 作为抽奖结果 是误人的。。。。
理想办法是生成抽奖池

然后以随机数的办法生成数据进入抽奖池中抽取奖品

并且加入判断语句来过滤已经抽取出来的奖品 一直到奖池为空

『贰』 求Java实现转盘转动功能,抽奖,坐等

转盘转动就是图片,定义一个随机数random;
if(random==1){
画中奖的图片
}else{
画不中奖的图片}

『叁』 用java怎么实现控制中奖率

可以做到!用 Random 得到随机的数,再根据你的登陆人的身份 控制随机的次数是多少!
例如:
1 - 20 为中奖, 普通就随机出 10000个数。会员的话就随机100个数就好了!

『肆』 求java算法:根据物品的数量来确定抽奖的概率(当物品数量为0时无论如何都不可能选到)

public class Lottery {

private int m = 1000;//发放奖券的数量
private int n = 2;//奖品的数量

public boolean getLottery(){
boolean isLottery = false;
double d = (double)n/(double)m;//中奖概率
double r = Math.random();//0~1之间的随机数,包括0
if(r<d){//如果随版机数小于权概率 那么中奖
n--;//奖品数量-1
isLottery = true;
}
m--;//奖券数量-1
return isLottery;
}

}

『伍』 java抽奖程序,可设置不同奖品获得概率

importjava.awt.EventQueue;
importjava.awt.TextArea;
importjava.awt.TextField;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.util.Random;

importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JPanel;
importjavax.swing.JTextArea;
importjavax.swing.JTextField;
importjavax.swing.border.EmptyBorder;


{

privateJPanelcontentPane;
privateJTextFieldtextFieldA;
privateJTextFieldtextFieldB;
privateJTextFieldtextFieldC;
privateTextFieldtextField;
;
privateJTextAreatextArea;
/**
*Launchtheapplication.
*/
publicstaticvoidmain(String[]args){
.invokeLater(newRunnable(){
publicvoidrun(){
try{
LuckySelectframe=newLuckySelect();
frame.setVisible(true);
}catch(Exceptione){
e.printStackTrace();
}
}
});
}

/**
*Createtheframe.
*/
publicLuckySelect(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100,100,450,251);
contentPane=newJPanel();
contentPane.setBorder(newEmptyBorder(5,5,5,5));
contentPane.setLayout(null);
setContentPane(contentPane);

JLabellblA=newJLabel("A");
lblA.setBounds(10,128,54,15);
contentPane.add(lblA);

JLabellblB=newJLabel("B");
lblB.setBounds(124,128,54,15);
contentPane.add(lblB);

JLabellblC=newJLabel("C");
lblC.setBounds(254,128,54,15);
contentPane.add(lblC);

textFieldA=newJTextField();
textFieldA.setBounds(30,125,66,21);
contentPane.add(textFieldA);
textFieldA.setColumns(10);

textFieldB=newJTextField();
textFieldB.setColumns(10);
textFieldB.setBounds(149,125,66,21);
contentPane.add(textFieldB);

textFieldC=newJTextField();
textFieldC.setColumns(10);
textFieldC.setBounds(264,125,66,21);
contentPane.add(textFieldC);

textField=newTextField();
textField.setBounds(98,167,157,21);
contentPane.add(textField);
textField.setColumns(10);

textFieldResult=newJTextField();
textFieldResult.setBounds(280,167,66,21);
contentPane.add(textFieldResult);
textFieldResult.setColumns(10);
textFieldA.setText("10");
textFieldB.setText("10");
textFieldC.setText("10");

JButtonbutton=newJButton("u62BDu5956");
button.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
select();
}
});
button.setBounds(0,166,93,23);
contentPane.add(button);

textArea=newJTextArea();
textArea.setBounds(30,31,306,83);
contentPane.add(textArea);
}

protectedvoidselect(){
//TODOAuto-generatedmethodstub
intaNum=Integer.decode(textFieldA.getText());
intbNum=Integer.decode(textFieldB.getText());
intcNum=Integer.decode(textFieldB.getText());
Randomr=newRandom();
intrandom=r.nextInt(aNum+bNum+cNum);
if(random<=aNum){
textFieldA.setText(Integer.toString(Integer.decode(textFieldA.getText())-1));
textArea.append(Integer.toString(random)+"抽中了A ");
}elseif(random<=aNum+bNum){
textFieldB.setText(Integer.toString(Integer.decode(textFieldB.getText())-1));
textArea.append(Integer.toString(random)+"抽中了B ");
}elseif(random<=aNum+bNum+cNum){
textFieldC.setText(Integer.toString(Integer.decode(textFieldC.getText())-1));
textArea.append(Integer.toString(random)+"抽中了C ");
}

}
}

阅读全文

与java大转盘根据中奖概率中奖相关的资料

热点内容
word兼容包安装报错 浏览:528
iphone5s包装4g没有气孔 浏览:814
html包含文件代码吗 浏览:50
苹果appstore日本账号 浏览:532
解密dg加密的文件 浏览:206
gsh6什么格式文件 浏览:507
dnf85版本觉醒任务 浏览:998
范冰冰苹果百度云盘资源链接 浏览:507
数据库主机是什么系统 浏览:812
pdf表单教程 浏览:715
百度浏览器去更新安卓破解版 浏览:855
光盘内部应用程序错误 浏览:83
iphone6升级ios9步骤 浏览:873
魔力代码 浏览:497
win10打开局域网文件夹很卡 浏览:986
app收益怎么分 浏览:812
我的世界什么版本好玩 浏览:341
控制专硕如何报考编程 浏览:534
元祖在编程里是什么意思 浏览:491
小码王为什么比核桃编程贵 浏览:627

友情链接