我目前正在进行假驾驶员教育测试。正如预期的那样,如果用户得到15个或更多正确的用户通过的问题,则用户必须回答20个问题。如果用户得到15个或更少的问题,则用户失败。
设计:URL to a picture of my current GUI
到目前为止,在Google的帮助下,我已经实现了我的密钥数组
string[] key = new string[20];
key[0] = "B";
key[1] = "D";
key[2] = "A";
key[3] = "A";
key[4] = "C";
key[5] = "A";
key[6] = "B";
key[7] = "A";
key[8] = "C";
key[9] = "D";
key[10] = "B";
key[11] = "C";
key[12] = "D";
key[13] = "A";
key[14] = "D";
key[15] = "C";
key[16] = "C";
key[17] = "B";
key[18] = "D";
key[19] = "A";
我还有用户创建的数组,当用户将他们的答案输入文本框以及输出数组以显示输入时,将创建该数组,但我认为我不需要它:
// User input
string[] values = new string[20];
values[0] = textBox1.Text;
values[1] = textBox2.Text;
values[2] = textBox3.Text;
values[3] = textBox4.Text;
values[4] = textBox5.Text;
values[5] = textBox6.Text;
values[6] = textBox7.Text;
values[7] = textBox8.Text;
values[8] = textBox9.Text;
values[9] = textBox10.Text;
values[10] = textBox11.Text;
values[11] = textBox12.Text;
values[12]= textBox13.Text;
values[13] = textBox14.Text;
values[14] = textBox15.Text;
values[15] = textBox16.Text;
values[16] = textBox17.Text;
values[17] = textBox18.Text;
values[18] = textBox19.Text;
values[19] = textBox20.Text;
// Displays selection (may not be needed)
textBox1.Text = values[0];
textBox2.Text = values[1];
textBox3.Text = values[2];
textBox4.Text = values[3];
textBox4.Text = values[4];
textBox6.Text = values[5];
textBox7.Text = values[6];
textBox8.Text = values[7];
textBox9.Text = values[8];
textBox10.Text = values[9];
textBox11.Text = values[10];
textBox12.Text = values[11];
textBox13.Text = values[12];
textBox14.Text = values[13];
textBox15.Text = values[14];
textBox16.Text = values[15];
textBox17.Text = values[16];
textBox18.Text = values[17];
textBox19.Text = values[18];
textBox20.Text = values[19];
我的问题有两个:
1.。)我如何将这些值数组与Key数组进行比较,如果用户输入D而不是B,则数组[0]将被计为错误?
2.。)我将如何显示“正确”和“错误”数组。
如果我的问题是模糊的,不够精确,或者我需要提供更多信息,请询问。我只是要求一些建议和指导。谢谢
答案 0 :(得分:0)
希望它会有所帮助:
String key[] = {"B","C","A","C"};
String values[] = {"B","C","B","A"};
int marks=0;
for(int i=0 ; i<key.length ; i++) {
if(key[i].equals(values[i])) {
System.out.println("Correct Answer");
++marks;
}
else {
System.out.println("Wrong!!!!!.For Question "+i+" Answer is "+key[i]);
}
if(marks>=15) {
System.out.println("Congratzzz!!You passed.");
} else {
System.out.println("Sorry!!You couldnt make it.");
}
}