用java模擬世界杯賽程抽簽的步驟:
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業的熱愛。我們立志把好的技術通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:域名申請、虛擬主機、營銷軟件、網站建設、保定網站維護、網站推廣。
1、東道主自動進入A組,并占據A1位置,其他七個種子隊將按照從B到H的順序,被抽入對應組的第一位。
2、確定每個小組的種子隊后,再按順序抽出第二檔球隊進入八個小組,然后是第三檔球隊,最后則是第四檔球隊。
3、后三檔球隊抽簽時,首先抽取所屬小組,再確定該隊在小組的位置(2、3、4)。
4、整個抽簽過程都將采取同洲回避原則,即同一大洲球隊不能同組,歐洲除外,但每組最多不能超過兩支歐洲球隊。
沒有學到圖形界面
要純編碼的話發個郵箱來,希望可以幫助你
import?java.awt.GridLayout;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.util.ArrayList;
import?java.util.regex.Pattern;
import?javax.swing.JButton;
import?javax.swing.JFrame;
import?javax.swing.JPanel;
import?javax.swing.JTextArea;
import?javax.swing.JTextField;
class?People
{
private?String?name;
private?int?id;
public?People(String?name)
{
this.name?=?name;
}
public?void?setID(int?id)
{
this.id?=?id;
}
public?String?getName()
{
return?name;
}
public?int?getId()
{
return?id;
}
}
public?class?test3?extends?JPanel
{
private?JTextArea?jtText;
private?JButton?jbOK;
private?People[]?peoples;
public?test3()
{
this.setLayout(new?GridLayout(1,?2));
jtText?=?new?JTextArea();
this.add(jtText);
jbOK?=?new?JButton("抽簽");
this.add(jbOK);
jbOK.addActionListener(new?ActionListener()
{
@Override
public?void?actionPerformed(ActionEvent?e)
{
//?TODO?Auto-generated?method?stub
String[]?names?=?jtText.getText().split("\n");
int?count?=?Integer.parseInt(names[0]);
peoples?=?new?People[count];
boolean[]?hasVisited?=?new?boolean[count?+?1];
for(int?i?=?0?;?i??count?;?i++)
{
peoples[i]?=?new?People(names[i+1]);
int?r;
while(true)
{
r?=?(int)(Math.random()?*?count)?+?1;
if(!hasVisited[r])
{
peoples[i].setID(r);
hasVisited[r]?=?true;
break;
}
}
}
String?text?=?"";
for(int?i?=?0?;?i??count?;?i++)
{
text?+=?peoples[i].getName();
text?+=?"????";
text?+=?peoples[i].getId();
text?+=?"\n";
}
jtText.setText(text);
}
});
}
public?static?void?main(String[]?args)
{
test3?panel?=?new?test3();
JFrame?frame?=?new?JFrame();
frame.add(panel);
frame.setSize(300,300);
frame.setVisible(true);
}
}
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Random;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Ballot extends JFrame implements ActionListener,KeyListener{
//窗口組建,成員變量
JTextArea _txt;
JButton _ballot;
JTextField _print;
JScrollPane _panel;
int n_o_p;
int index;
int _index;
String[] names;
static VectorInteger num=new VectorInteger();
static Random r=new Random();
//
boolean num_print=true;
public static void main(String[] args) {
new Ballot();
}
public Ballot()
{
n_o_p=0;
index=0;
_index=0;
_txt=new JTextArea();
_txt.setText("請在上面輸入人數,按Enter結束!");
_txt.setEditable(false);
_panel=new JScrollPane(_txt);
_ballot=new JButton("抽簽");
_print=new JTextField(10);
this.setLayout(new BorderLayout());
this.add(_panel,BorderLayout.CENTER);
this.add(_print,BorderLayout.NORTH);
this.add(_ballot,BorderLayout.SOUTH);
_print.addKeyListener(this);
_ballot.addActionListener(this);
this.setVisible(true);
this.setSize(new Dimension(400,200));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==_ballot)
{
if(index==n_o_p_index!=index)
{
boolean _b=true;
while(_b)
{
int _i=r.nextInt(index);
for(int i=0;inum.size();i++)
{
if(_i==num.get(i))
{
num.remove(i);
_txt.append("\r\n序號"+_i+" 姓名:"+names[_index]);
_index++;
_b=false;
}
}
}
}
if(_index==index)
{
File f=new File(System.getProperty("user.dir")+"/Save.txt");
if(f.exists())
{
try {
OutputStreamWriter ow=new OutputStreamWriter(new FileOutputStream(f));
ow.write(_txt.getText());
ow.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}else
{
try {
f.createNewFile();
OutputStreamWriter ow=new OutputStreamWriter(new FileOutputStream(f));
ow.write(_txt.getText());
ow.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}finally
{
_txt.setText("信息以保存至"+f.getPath()+"下!");
}
}
}
}
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
if(e.getKeyCode()==KeyEvent.VK_ENTER)
{
if(num_print){
if(_print.getText().matches("[0-9]+"))
{
num_print=false;
n_o_p=Integer.parseInt(_print.getText());
names=new String[n_o_p];
_print.setText("");
_txt.setText("還需要輸入"+n_o_p+"個人名!按回車完成單個人名輸入!");
}else
{
_txt.setText("輸入的人數非法!請重新輸入!");
}
}else
{
if(_print.getText()!=null!_print.getText().equals("")index!=n_o_p)
{
names[index]=_print.getText();
index++;
_txt.setText("還需要輸入"+(n_o_p-index)+"個人名!按回車完成單個人名輸入!");
}
}
if(index==n_o_p)
{
for(int i=0;iindex;i++)
{
num.add(i);
}
_txt.setText("請點擊按鈕進行抽簽!");
}
}
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
}
當前題目:抽簽代碼java 抽簽代碼腳本
鏈接URL:http://vcdvsql.cn/article18/ddigcdp.html
成都網站建設公司_創新互聯,為您提供品牌網站制作、網站維護、網站建設、電子商務、全網營銷推廣、Google
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯