Code for Main:
Errors for it:1 import java.util.ArrayList; 2 import java.util.Scanner; 3 4 public class Main { 5 6 public static void main(String[] args) { 7 ArrayList<Trivia> Questions = new ArrayList<>(); 8 Questions.add(new Trivia("q1", "yes")); 9 Questions.add(new Trivia("q2", "2")); 10 Questions.add(new Trivia("q3", "5")); 11 int score = DoTrivia(Questions); 12 Results(score); 13 } 14 15 public static int DoTrivia(ArrayList<> q) { 16 int Score = 0; 17 Scanner scanner = new Scanner(System.in); 18 for (int i = 0; i < q.size(); i++) { 19 System.out.println(q.get(i)); 20 String input = scanner.next(); 21 if (input.toLowerCase().equals(q.get(i).qAns)) { 22 Score++; 23 System.out.println("Correct! You have " + Score + " points!"); 24 } else { 25 System.out.println("Incorrect. The answer was " + q.get(i) + ". You have " + Score + " points."); 26 } 27 } 28 scanner.close(); 29 return Score; 30 } 31 public static void Results(int Score){ 32 if (Score >= 2) { 33 System.out.println("You won with " + Score + " points!"); 34 } else { 35 System.out.println("You lost with " + Score + " points."); 36 } 37 } 38 }
Identifier expected:15
Cannot resolve symbol 'qAns':21
Code for Trivia class...:
Any ideas to better utilize the new class? (I made it as the new class was a requirement for the tutorial's exercise.)
Thanks!