QandA 程序循环 A 如果回答错误
QandA program loop A if answered incorrectly
我目前正在构建一个问答程序。但我卡住了,因为我想重复这个问题(如果用户仍然想继续回答问题,直到 she/he 退出游戏,则没有限制。)在正确回答之前,你不能移动到下一个。请帮帮我=.=
String twoanswer = "Stamp";
String tworesponse = "";
tworesponse = JOptionPane.showInputDialog("It goes all over the world, but always stays in a corner. What is that?\nhint:_ _ _ _ _");
if (tworesponse.equalsIgnoreCase(twoanswer))
{
JOptionPane.showMessageDialog(null, "You are correct!");
JOptionPane.showMessageDialog(null, "Question Number: 3");
}
else
{
JOptionPane.showMessageDialog(null, "You are wrong.");
int reply1 = JOptionPane.showConfirmDialog(null, "Want to try again?", "Try again?", JOptionPane.YES_NO_OPTION);
if (reply1 == JOptionPane.YES_OPTION)
{
JOptionPane.showMessageDialog(null, "Answer again!");
//repeat to tworesponse ( the question)
}
if (reply1 == JOptionPane.NO_OPTION)
{
int reply1dot1 = JOptionPane.showConfirmDialog(null, "Are you sure?", "Quit game?", JOptionPane.YES_OPTION);
if (reply1dot1 == JOptionPane.YES_OPTION)
{
JOptionPane.showMessageDialog(null, "Thank you for playing!");
System.exit(0);
}
if (reply1dot1 == JOptionPane.NO_OPTION)
{
int reply1dot2 = JOptionPane.showConfirmDialog(null, "Try again?", "Try again?", JOptionPane.YES_NO_OPTION);
if (reply1dot2 == JOptionPane.YES_OPTION)
{
JOptionPane.showMessageDialog(null, "Answer again!");
//return to tworesponse question
}
if (reply1dot2 == JOptionPane.NO_OPTION)
{
JOptionPane.showMessageDialog(null, "Thank you for playing!");
System.exit(0);
}
}
}
}
}
}
这是一种伪代码,您可以将其更改为 java 代码:
for(Question question: questions){
Answer answer = askQuestion(Question)
if(question.answer = answer)
showInfo("you are correct, next question will be " + question.num + 1)
else{
response = showInfo("you are wrong. do you want to try?")
if(response = no)
break;
}
}
Answer askQuestion(Question question){
return showQuestion(question);
}
我目前正在构建一个问答程序。但我卡住了,因为我想重复这个问题(如果用户仍然想继续回答问题,直到 she/he 退出游戏,则没有限制。)在正确回答之前,你不能移动到下一个。请帮帮我=.=
String twoanswer = "Stamp";
String tworesponse = "";
tworesponse = JOptionPane.showInputDialog("It goes all over the world, but always stays in a corner. What is that?\nhint:_ _ _ _ _");
if (tworesponse.equalsIgnoreCase(twoanswer))
{
JOptionPane.showMessageDialog(null, "You are correct!");
JOptionPane.showMessageDialog(null, "Question Number: 3");
}
else
{
JOptionPane.showMessageDialog(null, "You are wrong.");
int reply1 = JOptionPane.showConfirmDialog(null, "Want to try again?", "Try again?", JOptionPane.YES_NO_OPTION);
if (reply1 == JOptionPane.YES_OPTION)
{
JOptionPane.showMessageDialog(null, "Answer again!");
//repeat to tworesponse ( the question)
}
if (reply1 == JOptionPane.NO_OPTION)
{
int reply1dot1 = JOptionPane.showConfirmDialog(null, "Are you sure?", "Quit game?", JOptionPane.YES_OPTION);
if (reply1dot1 == JOptionPane.YES_OPTION)
{
JOptionPane.showMessageDialog(null, "Thank you for playing!");
System.exit(0);
}
if (reply1dot1 == JOptionPane.NO_OPTION)
{
int reply1dot2 = JOptionPane.showConfirmDialog(null, "Try again?", "Try again?", JOptionPane.YES_NO_OPTION);
if (reply1dot2 == JOptionPane.YES_OPTION)
{
JOptionPane.showMessageDialog(null, "Answer again!");
//return to tworesponse question
}
if (reply1dot2 == JOptionPane.NO_OPTION)
{
JOptionPane.showMessageDialog(null, "Thank you for playing!");
System.exit(0);
}
}
}
}
}
}
这是一种伪代码,您可以将其更改为 java 代码:
for(Question question: questions){
Answer answer = askQuestion(Question)
if(question.answer = answer)
showInfo("you are correct, next question will be " + question.num + 1)
else{
response = showInfo("you are wrong. do you want to try?")
if(response = no)
break;
}
}
Answer askQuestion(Question question){
return showQuestion(question);
}