導航:首頁 > 編程語言 > java實現抽獎

java實現抽獎

發布時間:2021-12-08 18:27:13

Ⅰ 求java實現轉盤轉動功能,抽獎,坐等

轉盤轉動就是圖片,定義一個隨機數random;
if(random==1){
畫中獎的圖片
}else{
畫不中獎的圖片}

Ⅱ 用java怎麼實現控制中獎率

可以做到!用 Random 得到隨機的數,再根據你的登陸人的身份 控制隨機的次數是多少!
例如:
1 - 20 為中獎, 普通就隨機出 10000個數。會員的話就隨機100個數就好了!

Ⅲ 用java寫一個抽獎程序

這一百個隨機數給個范圍 random(范圍),再分批獲取唄 ,獲取到的數判斷在list里存在不,存在就重新獲取,不存在就添加到list中去

Ⅳ 用java做一個抽獎的代碼

要在cmd下運行啊 我想你安裝JDK沒?

import java.util.*;
class Test{
private int maxSize=0;
private int selectSize=0;
private List<Integer> list=new ArrayList<Integer>();
private int[] one=new int[7];
public Test(int maxSize,int selectSize){
this.maxSize=maxSize;
this.selectSize=selectSize;
one=new int[selectSize];
for(int i=1;i<=maxSize;i++)
list.add(Integer.valueOf(i));
}

public void open(){
List<Integer> temp=new ArrayList<Integer>();
temp.addAll(list);
int[] p=new int[selectSize];
int tag=0;
for(int i=0;i<selectSize;i++){
tag=(int)(Math.random()*555555%temp.size());
p[i]=(Integer)temp.get(tag).intValue();
temp.remove(tag);
}
one=p;

}
public void paixu(){
int temp=0;
for(int i=0;i<selectSize;i++){
for(int j=0;j<selectSize-1;j++){
if(one[j]>one[j+1]) {temp=one[j];one[j]=one[j+1];one[j+1]=temp;}
}
}
}

public void printOpen(){
open();
paixu();
for(int i=0;i<one.length;i++)
System.out.print(one[i]+" ");
System.out.println();
}
static public void main(String[] str){
Test t=new Test(33,6); //彩票類型:33選6
for(int i=0;i<10;i++) //開10次獎
t.printOpen();

}
}

Ⅳ 使用java語言編寫一個抽獎系統

packagech07;

importjavax.swing.*;

publicclassTest2{


publicstaticvoidmain(String[]args){
Stringoutput="";

output+="恭喜第"+(1+(int)(Math.random()*100))+"號中了一等獎";
output+=" 恭喜第"+(1+(int)(Math.random()*100))+"號"+(int)(1+(Math.random()*100))+"號"+"中了二等獎";
for(inti=0;i<3;i++){
output+=" 恭喜第"+(1+(int)(Math.random()*100))+"號中了三等獎";
}
JOptionPane.showMessageDialog(null,output);
}

}

程序運行結版果截圖

中獎的人權是隨機的!

Ⅵ java抽獎程序

我給你個比較簡單的,,但是需要按照你的要求進行稍微的修改。。然後在main方法中去執行就可以了:
public class GoodLuck {

int custNo;
int i=1;
String answer;
String awardName;
public void LuckNo(){

Scanner input=new Scanner(System.in);
System.out.println("\n我行我素購物管理系統 > 幸運抽獎\n");

do{
// 需要的話請把隨機數調整成你想要的范圍(我這個是為了測試方便寫的1
(~3的隨機數,根據你的需要把下面的3換成你想要的數字就行了)
int num=(int)(Math.random()*3+1);
System.out.print("請輸入會員卡號(4位整數):");
custNo=input.nextInt();
//百位數與隨機數相同的為幸運者
int =custNo/100%10;
while(i==1){
if(custNo>=1000&&custNo<=9999){
break;
}
else{
System.out.println("\n會員號碼輸入有誤,請重新輸入:");
custNo=input.nextInt();
continue;
}
}

if(==num){
showAward();
System.out.print("\n卡號:"+custNo+"是幸運客戶,獲得"+awardName);
}else{
System.out.print("\n卡號:"+custNo+"\t謝謝您的支持!");
}
System.out.println("\n是否繼續(y/n)");
answer=input.next();
while(i==1){
if(answer.equals("y")||answer.equals("n")){
break;
}else{
System.out.print("輸入有誤!請重新輸入:");
answer=input.next();
continue;
}
}
}while(!answer.equals("n"));

}
public void showAward(){
int num=(int)(Math.random()*3+1);
if(num==1){
awardName="Mp3";
}
else if(num==2){
awardName="美的微波爐";
}
else{
awardName="美的電飯鍋";
}

}

Ⅶ 如何用java技術實現幸運抽獎活動系統

import java.util.Scanner;
public class LuckyNumber {
/**
* 幸運抽獎
*/
public static
void main(String[] args) {
String answer
= "y"; // 標識是否繼續
String
userName = ""; // 用戶名
String
password = ""; // 密碼
int cardNumber
= 0; // 卡號
boolean
isRegister = false; // 標識是否注冊
boolean
isLogin = false; // 標識是否登錄
int max =
9999;
int min =
1000;
Scanner input
= new Scanner(System.in);
do {
System.out.println("*****歡迎進入獎客富翁系統*****");
System.out.println("\t1.注冊");
System.out.println("\t2.登錄");
System.out.println("\t3.抽獎");
System.out.println("***************************");
System.out.print("請選擇菜單:");
int choice =
input.nextInt();
switch
(choice) {
case 1:
System.out.println("[獎客富翁系統
> 注冊]");
System.out.println("請填寫個人注冊信息:");
System.out.print("用戶名:");
userName =
input.next();
System.out.print("密碼:");
password =
input.next();
//
獲取4位隨機數作為卡號
cardNumber =
(int)(Math.random()*(max-min))+min;
System.out.println("\n注冊成功,請記好您的會員卡號");
System.out.println("用戶名\t密碼\t會員卡號");
System.out.println(userName
+ "\t" + password + "\t" + cardNumber);
isRegister =
true; // 注冊成功,標志位設置為true
break;
case 2:
System.out.println("[獎客富翁系統
> 登錄]");
if
(isRegister) { // 判斷是否注冊
//
3次輸入機會
for (int i
= 1; i <= 3; i++) {
System.out.print("請輸入用戶名:");
String
inputName = input.next();
System.out.print("請輸入密碼:");
String
inputPassword = input.next();
if
(userName.equals(inputName) && password.equals(inputPassword)) {
System.out.println("\n歡迎您:"
+ userName);
isLogin =
true; // 登錄成功,標志位設置為true
break;
} else if
(i < 3) {
System.out.println("用戶名或密碼錯誤,還有"
+ (3 - i) + "次機會!");
} else
{
System.out.println("您3次均輸入錯誤!");
}
}
} else
{
System.out.println("請先注冊,再登錄!");
}
break;
case 3:
System.out.println("[獎客富翁系統
> 抽獎]");
if
(!isLogin) { // 判斷是否登錄
System.out.println("請先登錄,再抽獎!");
} else
{
//生成5個4位隨機數字,並保存在數組中
int[]
luckynums = new int[5];
for(int i
= 0; i < luckynums.length; i++){
luckynums[i] =
(int)(Math.random()*(max-min))+min;
}
System.out.print("請輸入您的卡號:");
int
yourcard = input.nextInt();
int
i;
System.out.print("\n本日的幸運數字為:");
for (i = 0;
i < luckynums.length; i++) {
System.out.print(luckynums[i]
+ " ");\
}
for (i = 0;
i < luckynums.length; i++) {
if
(luckynums[i] == yourcard) {
System.out.println("\n恭喜!您是本日的幸運會員!");
break;
}
}

if (i ==
luckynums.length) {
System.out.println("\n抱歉!您不是本日的幸運會員!");
}
}
break;
default:
System.out.println("[您的輸入有誤!]");
break;
}
System.out.print("繼續嗎?(y/n):");
answer =
input.next();
System.out.println("");
} while
("y".equals(answer));
if
("n".equals(answer)) {
System.out.println("系統退出,謝謝使用!");

}

}
}

Ⅷ 做一個JAVA的抽獎系統

用隨機的辦法 來 作為抽獎結果 是誤人的。。。。
理想辦法是生成抽獎池

然後以隨機數的辦法生成數據進入抽獎池中抽取獎品

並且加入判斷語句來過濾已經抽取出來的獎品 一直到獎池為空

Ⅸ 關於java抽獎代碼

if (b==1);{
System.out.println("您抽到的是一等獎");)
}
好像是少了{}
程序從上往下讀的 System.out.println("您抽到的是一等獎"); 不在if的裡面。

Ⅹ 以JAVA為平台實現搖號抽獎

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;

import java.util.*;

import java.io.FileReader;
import java.io.File;

// This example demonstrates the use of JButton, JTextField
// and JLabel.
public class LunarPhases implements ActionListener {
final static int NUM_IMAGES = 1000;

final static int START_INDEX = 0;

int REAL_NUM_IMAGES = 0;

ImageIcon[] images = new ImageIcon[NUM_IMAGES];

String[] imageNames = new String[NUM_IMAGES];

JPanel mainPanel, selectPanel, displayPanel, resultPanel;

JButton phaseChoice = null;

JLabel phaseIconLabel = null, phaseResult = null;

// Constructor
public LunarPhases() {
// Create the phase selection and display panels.
selectPanel = new JPanel();
displayPanel = new JPanel();
resultPanel = new JPanel();

// Add various widgets to the sub panels.
addWidgets();

// Create the main panel to contain the two sub panels.
mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(1, 3, 5, 5));
mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

// Add the select and display panels to the main panel.
mainPanel.add(selectPanel);
mainPanel.add(displayPanel);
mainPanel.add(resultPanel);
}

// Create and the widgets to select and display the phases of the moon.
private void addWidgets() {
// Get the images and put them into an array of ImageIcon.
File dir = new File("C:\\Program Files\\JavaSoft\\JDK1.3.1\\bin\\images");
File[] files = dir.listFiles();
String imageName = null;
String temp = null;
int j = 0;
for (int i = 0; i < files.length; i++) {
if (!files[i].isDirectory()) {
imageName = "images/" + files[i].getName();
}
temp = imageName.substring(imageName.lastIndexOf(".") + 1, imageName.length());
if(!temp.equals("gif"))
{
continue;
}
URL iconURL = ClassLoader.getSystemResource(imageName);
ImageIcon icon = new ImageIcon(iconURL);
images[j] = icon;
imageNames[j] = imageName.substring(7,imageName.lastIndexOf("."));
j++;
}
REAL_NUM_IMAGES = j;

// Create label for displaying moon phase images and put a border around
// it.
phaseIconLabel = new JLabel();
phaseIconLabel.setHorizontalAlignment(JLabel.CENTER);
phaseIconLabel.setVerticalAlignment(JLabel.CENTER);
phaseIconLabel.setVerticalTextPosition(JLabel.CENTER);
phaseIconLabel.setHorizontalTextPosition(JLabel.CENTER);
phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLoweredBevelBorder(), BorderFactory
.createEmptyBorder(5, 5, 5, 5)));

phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(0, 0, 10, 0), phaseIconLabel
.getBorder()));

phaseResult = new JLabel();

// Create combo box with lunar phase choices.
phaseChoice = new JButton("開始/停止");

// Display the first image.
phaseIconLabel.setIcon(images[START_INDEX]);
phaseIconLabel.setText("");

// Add border around the select panel.
selectPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createTitledBorder("Select Phase"), BorderFactory
.createEmptyBorder(5, 5, 5, 5)));

resultPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createTitledBorder("Result Phase"), BorderFactory
.createEmptyBorder(5, 5, 5, 5)));

// Add border around the display panel.
displayPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createTitledBorder("Display Phase"), BorderFactory
.createEmptyBorder(5, 5, 5, 5)));

// Add moon phases combo box to select panel and image label to
// displayPanel.
selectPanel.setLayout(new GridLayout(3,3));//這里原來是selectPanel.add(phaseChoice);
// displayPanel.add(phaseIconLabel);
// resultPanel.add(phaseResult);

selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(phaseChoice);
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
resultPanel.setLayout(new BorderLayout());
displayPanel.add(phaseIconLabel);
resultPanel.add(phaseResult);

// Listen to events from combo box.
phaseChoice.addActionListener(this);
}

boolean run = false;
// Implementation of ActionListener interface.
public void actionPerformed(ActionEvent event) {
if(run){
run = false;
}
else{
run = true;
new Thread(){
public void run(){
while(run){
int a =(int)( Math.random()*REAL_NUM_IMAGES);
phaseIconLabel.setIcon(images[a]);
phaseResult.setText(imageNames[a]);
try{
Thread.sleep(100);
}
catch(Exception e){}
}
}
}.start();
}
}

// main method
public static void main(String[] args) {
// create a new instance of LunarPhases
LunarPhases phases = new LunarPhases();

// Create a frame and container for the panels.
JFrame lunarPhasesFrame = new JFrame("Lunar Phases");

// Set the look and feel.
try {
UIManager.setLookAndFeel(UIManager
.());
} catch (Exception e) {
}

lunarPhasesFrame.setContentPane(phases.mainPanel);

// Exit when the window is closed.
lunarPhasesFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Show the converter.
lunarPhasesFrame.pack();
lunarPhasesFrame.setVisible(true);
}
}

閱讀全文

與java實現抽獎相關的資料

熱點內容
iphone5c黑色 瀏覽:374
河南少兒計算機編程加盟怎麼樣 瀏覽:135
共享文件夾可以共享多少個 瀏覽:197
文愛用什麼app 瀏覽:920
導致iis死機代碼 瀏覽:280
iphone5c電池電壓不足 瀏覽:639
javatcp通信 瀏覽:189
傳奇永恆140升級攻略 瀏覽:421
win10小娜文件損壞 瀏覽:643
寫作時用什麼樣的網路用語 瀏覽:696
官網正版win10系統 瀏覽:111
iphone4s升級固件 瀏覽:228
外國小孩為主角的電影 瀏覽:650
老電影60年代戰爭片 瀏覽:299
百度雲同步盤文件丟失 瀏覽:833
穿越從永無止境電影世界開始 瀏覽:572
逆戰聖光升級鷹王好嗎 瀏覽:770
win10向虛擬機傳文件 瀏覽:181
女主叫小雨 瀏覽:255
電腦的投標文件 瀏覽:108

友情鏈接