所以我对我的java编程非常生疏。我正在尝试创建一个假设的公司彩票,每个员工只能进入一次。然后将随机生成一个名字来宣布获胜者。我什至不确定我现在有一些事情的顺序是正确的。对此的任何帮助将不胜感激。我查了一些东西,我相信它使情况变得更糟。
// instance variables
final int NUM_PARTIC = 7; // number of workers participating
String input; // holds each name
int i, j;
// Create array to hold number of particpants.
String[] nameArray = new String[NUM_PARTIC];
// Create a Random class object.
Random stakes = new Random();
for(i = 0; i < nameArray.length; i++)
{
// Prompt participant for name.
input = JOptionPane.showInputDialog(null, "Please enter your"
+ " name into our database:", "Entry", JOptionPane.QUESTION_MESSAGE);
nameArray[i] = input; // Store name in namesArray[]
// Prompt next participant for name
input = JOptionPane.showInputDialog(null, "Please enter your name into our"
+ " database:", "Entry", JOptionPane.QUESTION_MESSAGE);
nameArray[i] = input; // Store name in namesArray[]
for(j = i + 1; j < nameArray.length; ++j)
{
JOptionPane.showMessageDialog(null, "Sorry, this name is already "
+ "in our database", "Invalid", JOptionPane.ERROR_MESSAGE);
input = JOptionPane.showInputDialog(null, "Please enter your name into our"
+ " database:", "Entry", JOptionPane.QUESTION_MESSAGE);
}
// Display winner
JOptionPane.showMessageDialog(null, "The winner for today's raffle "
+ "is: " + nameArray[i], "Winner",
JOptionPane.WARNING_MESSAGE);
// Exit program
System.exit(0);