I have a drivers license test program where in the main method the user inputs the answers then in a separate class there needs to be a method to see if the user passed a method to tell how many were wrong and right and a method put the numbers of the answers which were wrong into an array then the main method needs to print out the results of each of those methods. my issues is with the array of the problem numbers that were wrong . I believe I correctly created it but I cant get the main method to print it out.Thanks
public class DriverExam { static String[] correctAnswers={"b","d","a","a","c","a","b","a","c","d","b","c","d","a","d","c","c","b","d","a"}; static String[] userAnswers=new String[20]; //constructer public DriverExam(String[] user) { userAnswers=user; } //method to see if you passed public static boolean passed() { boolean pass=false; int correctCount=0; int incorrectCount=0; for(int i=0;i<userAnswers.length;i++) { if(userAnswers[i].equals(correctAnswers[i])) { correctCount++; } else { incorrectCount++; } } if(correctCount>14) {pass=true;} return pass; } //method to find number correct public static int totalCorrect() { boolean pass=false; int correctCount=0; int incorrectCount=0; for(int i=0;i<userAnswers.length;i++) { if(userAnswers[i].equals(correctAnswers[i])) { correctCount++; } else { incorrectCount++; } } return correctCount; } //method to tell how many were not correct public static int totalIncorrect() { boolean pass=false; int correctCount=0; int incorrectCount=0; for(int i=0;i<userAnswers.length;i++) { if(userAnswers[i].equals(correctAnswers[i])) { correctCount++; } else { incorrectCount++; } } return incorrectCount; } public static int[] questionsMissed() { boolean pass=false; int correctCount=0; int incorrectCount=0; for(int i=0;i<userAnswers.length;i++) { if(userAnswers[i].equals(correctAnswers[i])) { correctCount++; } else { incorrectCount++; } } int[] questionWrong=new int[incorrectCount]; for(int i=0;i<questionWrong.length;i++) { if(!userAnswers[i].equals(correctAnswers[i])) {i=questionWrong[i]; } } return questionWrong; } }
import java.util.Scanner; public class DriverExamDemo { public static void main(String[] args) { String[] userAnswers=new String[20]; String answer; System.out.println("please enter the testee's answers as the correspond with the question number"); for(int i=0;i<userAnswers.length;i++) { Scanner input=new Scanner(System.in); System.out.println("Q."+(i+1)); answer=input.next(); userAnswers[i]=answer; } // constructor to send the users answers DriverExam exam1 = new DriverExam(userAnswers); //Check passed boolean to see if the user passed or failed if(DriverExam.passed()) System.out.println("you passed your driving exam"); else System.out.println("you failed your driving exam"); //check how many answers were correct and incorrect System.out.println("you answered "+DriverExam.totalCorrect()+" questions correctly"); System.out.println("you answered "+DriverExam.totalIncorrect()+" questions incorrectly"); int[] questionsWrong=DriverExam.questionsMissed(); for (int i=0;i<questionsWrong.length;i++) { System.out.println("you got question " +questionsWrong[i]+"incorrect"); } } }