大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
用java模拟世界杯赛程抽签的步骤:
我们提供的服务有:做网站、成都网站建设、微信公众号开发、网站优化、网站认证、襄州ssl等。为1000+企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的襄州网站制作公司
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
}
}