Java 没有任何东西从主方法启动

Java 没有任何东西从主方法启动,java,arrays,methods,implementation,main,Java,Arrays,Methods,Implementation,Main,当我从下面的3个类文件启动我的程序时,什么都没有发生。它只显示一个空控制台。我是否缺少某种实现或其他东西?它由3个类文件组成,我没有来自编译器的错误消息。程序只需显示每个测验问题,玩家回答,然后在最后获得最终分数。谢谢 public class Question { private String question, answer; //----------------------------------------------------------------- //

当我从下面的3个类文件启动我的程序时,什么都没有发生。它只显示一个空控制台。我是否缺少某种实现或其他东西?它由3个类文件组成,我没有来自编译器的错误消息。程序只需显示每个测验问题,玩家回答,然后在最后获得最终分数。谢谢

public class Question 
{
   private String question, answer;


   //-----------------------------------------------------------------
   //  Constructor: Sets up the question with a default complexity.
   //-----------------------------------------------------------------
   public Question (String query, String result)
   {
      question = query;
      answer = result;

   }



   //-----------------------------------------------------------------
   //  Returns the question.
   //-----------------------------------------------------------------
   public String getQuestion()
   {
      return question;
   }

   //-----------------------------------------------------------------
   //  Returns the answer to this question.
   //-----------------------------------------------------------------
   public String getAnswer()
   {
      return answer;
   }

   //-----------------------------------------------------------------
   //  Returns true if the candidate answer matches the answer.
   //-----------------------------------------------------------------
   public boolean answerCorrect (String candidateAnswer)
   {
      return answer.equals(candidateAnswer);
   }

   //-----------------------------------------------------------------
   //  Returns this question (and its answer) as a string.
   //-----------------------------------------------------------------
   public String toString()
   {
      return question + "\n" + answer;
   }
}

import java.util.Scanner;
public class Quiz

{
private int score;
private Question[] questionHolder = new Question[25];
private int numQuestions;



public Quiz()
{
this.score = 0;
this.numQuestions = 0;

}

public void addQuestion (Question Q)
{
this.questionHolder[numQuestions++] = Q;
}

public int giveQuiz()

{

Scanner scan = new Scanner (System.in);

String candidateAnswer;


scan.nextInt();
scan.nextLine();


for (int i = 0; i < numQuestions; i++)
{

candidateAnswer = scan.nextLine();
if (questionHolder.answerCorrect(candidateAnswer))
score++;
}
return getscore();
}
public int getscore()
{
return score;
}
public String toString()
{
return getscore() + "\n";
}

}

public class QuizTime

{
public static void main (String[] args)

{
//--------------------------------------------------------------------------
//Initializes the variables.
//--------------------------------------------------------------------------
Question Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19,
Q20, Q21, Q22, Q23, Q24, Q25;

Quiz T1;

//--------------------------------------------------------------------------
//Creates the question and answer and also sets its complexity value.
//--------------------------------------------------------------------------
Q1 = new Question ("What is the capital of Virginia?", "Richmond");

Q2 = new Question ("Is an apple a Fruit or a vegetable?", "Fruit");

Q3 = new Question ("What continent is China in?", "Asia");

Q4 = new Question ("Is Germany in Europe or South America?", "Europe");

Q5 = new Question ("What color is a black bear?", "Black");

Q6 = new Question ("What is the capital of Arizona?", "Phoenix");

Q7 = new Question ("What do cows produce??", "Milk");

Q8 = new Question ("What ocean is closest to New York City?", "Atlantic");

Q9 = new Question ("What ocean surrounds Japan?", "Pacific");

Q10 = new Question ("What is the largest state in America?", "Alaska");

Q11 = new Question ("What is the smallest state?", "Deleware");

Q12 = new Question ("What is the most populated state?", "California");

Q13 = new Question ("What is instrument did Jascha Heifetz play?", "Violin");

Q14 = new Question ("Was Mozart a composer or a computer?", "Composer");

Q15 = new Question ("What is the largest country by area?", "Russia");

Q16 = new Question ("What is the most populated country?", "China");

Q17 = new Question ("What country did Pizza originate in?", "Italy");

Q18 = new Question ("What is the last name of the first American President?", "Washington");

Q19 = new Question ("What country borders America to the south?", "Mexico");

Q20 = new Question ("What island is 700 miles off the coast of NYC?", "Bermuda");

Q21 = new Question ("What city contains the Eiffel Tower?", "Paris");

Q22 = new Question ("Who wrote Romeo and Juliet?", "Shakespeare");

Q23 = new Question ("What swims in the ocean?", "Fish");

Q24 = new Question ("What is man's best friend?", "Dog");

Q25 = new Question ("What is another name for coffee and the language of this program?", "Java");


//--------------------------------------------------------------
//Adds the questions into quiz.
//--------------------------------------------------------------
T1= new Quiz();
T1.addQuestion(Q1);
T1.addQuestion(Q2);
T1.addQuestion(Q3);
T1.addQuestion(Q4);
T1.addQuestion(Q5);
T1.addQuestion(Q6);
T1.addQuestion(Q7);
T1.addQuestion(Q8);
T1.addQuestion(Q9);
T1.addQuestion(Q10);
T1.addQuestion(Q11);
T1.addQuestion(Q12);
T1.addQuestion(Q13);
T1.addQuestion(Q14);
T1.addQuestion(Q15);
T1.addQuestion(Q16);
T1.addQuestion(Q17);
T1.addQuestion(Q18);
T1.addQuestion(Q19);
T1.addQuestion(Q20);
T1.addQuestion(Q21);
T1.addQuestion(Q22);
T1.addQuestion(Q23);
T1.addQuestion(Q24);
T1.addQuestion(Q25);

//--------------------------------------------------------------
//Prints out the quizes.
//--------------------------------------------------------------
System.out.print(T1.giveQuiz());


}
}
公开课问题
{
私人串问题、答案;
//-----------------------------------------------------------------
//构造函数:使用默认复杂性设置问题。
//-----------------------------------------------------------------
公共问题(字符串查询、字符串结果)
{
问题=查询;
答案=结果;
}
//-----------------------------------------------------------------
//返回问题。
//-----------------------------------------------------------------
公共字符串getQuestion()
{
返回问题;
}
//-----------------------------------------------------------------
//返回此问题的答案。
//-----------------------------------------------------------------
公共字符串getAnswer()
{
返回答案;
}
//-----------------------------------------------------------------
//如果候选答案与答案匹配,则返回true。
//-----------------------------------------------------------------
公共布尔应答正确(字符串候选应答)
{
返回答案。等于(候选答案);
}
//-----------------------------------------------------------------
//以字符串形式返回此问题(及其答案)。
//-----------------------------------------------------------------
公共字符串toString()
{
返回问题+“\n”+答案;
}
}
导入java.util.Scanner;
公开课测验
{
个人智力得分;
私人问题[]问题持有者=新问题[25];
私有整数;
公开问答
{
这个分数=0;
this.numQuestions=0;
}
公众提问(问题Q)
{
这个.questionHolder[numQuestions++]=Q;
}
公共智力测验()
{
扫描仪扫描=新扫描仪(System.in);
字符串候选答案;
scan.nextInt();
scan.nextLine();
for(int i=0;i
此行有错误

if (questionHolder.answerCorrect(candidateAnswer)) // questionHolder is an array
由于
questionHolder
是一个数组,因此需要在循环中提供索引

if (questionHolder[i].answerCorrect(candidateAnswer)) // like this, [i] - index
此外,程序启动,但等待用户输入。疗法
// Waiting for the user to input an integer value, but there is no SOP to intimate the 
// user about it, thus making it seem like doing nothing.
scan.nextInt();
scan.nextLine();
for (int i = 0; i < numQuestions; i++) {
    System.out.println(questionHolder[i].getQuestion()); // Question is displayed to the user now. Answer accordingly.
    candidateAnswer = scan.nextLine();
    if (questionHolder[i].answerCorrect(candidateAnswer))
        score++;
}
// scan.nextInt();
// scan.nextLine();
System.out.print(T1.giveQuiz());
scan.nextInt();
scan.nextLine();
questionHolder[i].answerCorrect(candidateAnswer)
questionHolder.answerCorrect(candidateAnswer)
 System.out.println("Please type a string and and integer and hit return");
 System.out.print(T1.giveQuiz());