ArrayList Get - 错误:找不到符号

时间:2014-02-21 15:18:38

标签: java

我是enums和ArrayLists的新手,我被指派制作一个程序,在真或假的测验中评分15个答案。我的程序工作正常,直到.get函数,它放置无法找到符号错误。我不知道为什么。是否与一起使用字符串和我的枚举类型有关?

public enum acceptedAnswer {T, F}
public static void main(String[] args)
{
  Scanner scan  = new Scanner(System.in);
  String answerKey = "TTTFFTFFFTFFTTF";
  String temp = "";
  String userChoice;
  int numOfStudents = 0;


  int maxScore = 0;
    int maxId = 0;
    int minScore = 15;
    int minId = 0;
    int sumOfScores = 0;
  double average = 0.0;

  System.out.print("Enter the amount of students tests to be graded: ");
   numOfStudents = scan.nextInt();
  scan.nextLine();

  int[] score = new int[numOfStudents];
  acceptedAnswer[] answers = new acceptedAnswer[15];
  List student = new ArrayList();

        for (int j = 0; j < numOfStudents; j++)
  {
     for (int i = 0; i < 15; i++)
       {
           System.out.print("Enter the answer to question " + (i+1) + " for student " + (j+1) + ": ");
           userChoice = scan.nextLine();
        answers[i] = acceptedAnswer.valueOf(userChoice);
        temp += answers[i];
     }
      System.out.println();
     student.add(temp); 
     temp = "";
    }

    for (int i = 0; i < numOfStudents; i++)
    {
        for (int j = 0; j < 15; j++)
        {
        temp = answers.get(i);
            if (temp.charAt(j) == answerKey.charAt(j))
                score[i] ++;
        }
          sumOfScores += score[i];
        }

2 个答案:

答案 0 :(得分:0)

答案:数组不是ArrayList。将其声明为ArrayList或通过直接索引(如

)访问值
temp = answers[i]

答案 1 :(得分:0)

您需要替换

temp = answers.get(i);

temp = answers[i];

因为答案是一个数组。