導航:首頁 > 編程語言 > 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大轉盤根據中獎概率中獎相關的資料

熱點內容
我的世界什麼版本好玩 瀏覽:341
控制專碩如何報考編程 瀏覽:534
元祖在編程里是什麼意思 瀏覽:491
小碼王為什麼比核桃編程貴 瀏覽:627
qq下載app有哪些 瀏覽:380
旅遊app的社區模塊有什麼 瀏覽:847
盜版win7怎樣升級win10 瀏覽:524
怎麼壓縮文件夾不超過10mb 瀏覽:770
網路攝像頭如何外網訪問 瀏覽:178
刷入的cp文件是什麼 瀏覽:513
dcp文件是什麼 瀏覽:427
win10驅動刪不了怎麼辦啊 瀏覽:459
win7如何做共享文件夾圖標 瀏覽:178
魔獸120怎麼升級124 瀏覽:395
智能健康手錶下載什麼app 瀏覽:664
想在協和醫院掛號怎麼下載app 瀏覽:86
關於科技產品需要哪些數據 瀏覽:623
linux命令行修改文件內容 瀏覽:526
java通信框架有哪些 瀏覽:331
哪裡看美國報紙app 瀏覽:753

友情鏈接