【发布时间】:2017-12-13 13:42:06
【问题描述】:
我是 Java 新手,刚刚开始我的第一个半严肃的任务。我相信我的大部分代码都在工作,唯一的问题是因为我一直在使用类,我似乎无法将使用数组的方法调用到我的主类中。我想调用的所有其他方法似乎都有效。我想知道是否有人对此有任何解释或简单的解决方案?
提前感谢您花时间研究,非常感谢!
import java.util.Scanner;
public class GeographyQuizMain
{
public static void main(String[] args)
{
takeQuiz();
}
public static void takeQuiz(Question[][] questions)
{
int score = 0;
RandomNumber randomQuestion = new RandomNumber();
//user chooses catergory
int cat = pickCatergory();
//ask 10 questions
for(int i = 0; i < 10;)
{
Scanner answerChoice = new Scanner(System.in);
randomQuestion.dice();
int q = (randomQuestion.dice() - 1);
//checks to see if question as been asked before
if (!questions[cat][q].beenAsked)
{
questions[cat][q].beenAsked = true; //changes question status to beenAsked
System.out.println(questions[cat][q].promt);
String answer = answerChoice.nextLine();
System.out.println("\nYou picked: " + answer + "\nThe correct answer was: " + questions[cat][q].answer + "\n");
if(answer.equals(questions[cat][q].answer))
{
score++;
}
i++;
}
}
System.out.println("That is the end of the quiz!\n"
+ "You got " + score + "/10");
}
【问题讨论】:
-
向我们展示您在
Question课程中的内容