I'm new to both enums and ArrayLists, I was assigned to make a program to grade 15 answers in a True or False quiz. My program works fine up until the .get function where it puts the cannot find the symbol error. I'm not sure why at all. Is it something to do with using a string and my enum type together?
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];
}
Answer : An array is not an ArrayList. Declare it as an ArrayList or access the values by direct index like
temp = answers[i]
You need to replace
temp = answers.get(i);
with
temp = answers[i];
because answers is an array.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.