对于我的科学博览会项目,我想给一个法语教学程序提供一个图形更新,这个程序在DosBOX中已经很老了。这一切都很好,但我遇到了问题。我在控制台应用程序中编写程序的基本逻辑,只是为了将它们结合在一起。我创建了一个Question类,它位于数组列表/集合中,名为“test1”。重复一个循环的增量
我有一个列表并在每次迭代迭代,它运行称为另一种方法循环评估:
public static boolean evaluate(Question question, Scanner scanner)
{
System.out.println(question.getPhrase()); // prints the question
String answer = scanner.nextLine(); // gets the answer
if (answer.compareTo(question.getCorrectAnswer()) == 0)
return true; // compares the answer to the correct answer w/i the current instance of "Question"
else
return false; // if it's not right, returns "false" meaning the question wasn't correct
}
循环看起来这样:
for (Question question : test1)
{
if (evaluate(question, scan))
{
incorrect = 0;
continue;
}
else
{
incorrect++;
System.out.println(incorrect);
}
if (incorrect == 3)
System.out.println("you have failed");
break;
}
我想让它所以如果你错误地回答了一个问题,它会再次吐出这个短语,并将“不正确”加1,如果你打3,就终止列表(我想我已经正确实施了,如果我可以重复它问题)。现在它移动到列表中的下一个项目,因此下一个问题即使我不想要。
对不起,如果我的代码很糟糕,我还是比较新的编程。
您需要的循环中,您已经在另一个内部循环有,重复当前的问题,直到它被正确回答。 – 2014-10-04 17:50:49