随机测试生成器与类

时间:2014-12-05 22:51:47

标签: java arrays random

我对java比较陌生,我试图在一个名为TestGenerator的类中开发一个测试生成器程序,从一个字符串数组中的5个多项选择问题池中随机选择2个问题。我已经给出了在TestGenerator类中创建2行一维数组的提示,该数组将随机填充0到4之间的数字,这些数字将对应于数组TestBank中的问题。调用该数组SelectedNumbers。无论选择哪个数字,都会向用户询问这些问题。我希望通过不同的窗口分别提出问题,最后告诉我分数。截至目前,我有一个5乘5的字符串数组TestBank,其中第一列是问题,接下来的三个是答案选择,第五列是正确的答案。

public class TestGenerator {  


public static void main(String[] args) {

String TestBank[][] = {{"What color is grass?","A. Green","B. Red","C. Pink","A"},
{"Whats the first month called?","A. December","B. January","C. March","B"},
{"What shape is a soccer ball?","A. square","B. flat","C. round","C"},
{"what flys?","A. birds","B. pigs","C. dogs","A"},
{"what planet are we on?","A. Earth","B. Venus","C. Jupiter","A"}};


for(int i = 0; i < TestBank.length; i++) {
System.out.print(TestBank[i][0]+" ");

for(int j = 1; j < TestBank[i].length; j++) { 
System.out.print(TestBank[i][j]+" "); 
}
System.out.println();
}
}
}

我很难将从SelectedNumber数组中随机选择的数字连接到TestBank,并且难以将这些问题输出到不同的窗口中,如下所示:

input = JOptionPane.showInputDialog("What color is grass?\nA. green\nB. red\nC. pink");
number = Double.parseDouble(input);
kitchen.setLength(number);

如果有人能帮助我,我将深表感谢。我是Java的新手,所以请尽量保持简单,并向我解释如何解决这个问题。谢谢!

0 个答案:

没有答案