Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA ERROR: NO MAIN METHODS, APPLETS, OR MIDLETS FOUND IN THE FILE How do I fix

ID: 3776093 • Letter: J

Question

JAVA

ERROR: NO MAIN METHODS, APPLETS, OR MIDLETS FOUND IN THE FILE

How do I fix this?

public class DriverExam
{
//public static void main(String[] args);


   //student's answers
   private String[] correctAnswers =
   {"B", "D", "A", "A", "C", "A",
"B", "A", "C", "D",
"B", "C", "D", "A",
"D", "C", "C", "B", "D", "A"};

   //Store the student's answers
   private String[] userAnswers;
   int[] missed = new int[correctAnswers.length];

   //Process their answers
   public DriverExam (String[] Answers)
   {
userAnswers = new String[Answers.length];

for (int i = 0; i < Answers.length; i++)
{
   userAnswers[i] = Answers[i];
}
   }


   public boolean passed()
   {
if (totalCorrect() >= 15)
   return true;
else
   return false;
   }

   //total correct
   public int totalCorrect()
   {
int correctCount = 0;

for (int i = 0; i < correctAnswers.length; i++)
{
   if (userAnswers[i].equalsIgnoreCase(correctAnswers[i]))
   {
correctCount++;


}
}
return correctCount;
   }

   // total incorrect
   public int totalIncorrect()
   {
int incorrectCount = 0;

for (int i = 0; i < correctAnswers.length; i++)
{
   if (!userAnswers[i].equalsIgnoreCase(correctAnswers[i]))
   {
missed[incorrectCount] = 1;
incorrectCount++;
   }
}
return incorrectCount;
   }

   //missing
   public int[] questionsMissed()
   {
return missed;
   }

}
//end of DriverExam class

Explanation / Answer

I have added Main method in your function. This Method will accept answer from users.

And Ii will also check how many correct answres and how many incorrect answers are there.It will call totalCorrect() & totalInCorrect() from main method.

Finally it will check whether that student Passed or failed in exam.

CODE:

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class DriverExam

{

          public static void main(String[] args) throws IOException{

               BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

               String[] Answers = new String[20];

               System.out.println("Enter Answers:");

              for(int i=0;i<Answers.length;i++)

                  {

                          Answers[i]=br.readLine();

                   }

            DriverExam(Answers);

            System.out.println("Correct Answers::"+totalCorrect());

             System.out.println("InCorrect Answers::"+totalIncorrect());

              boolean pass=passed();

              if(pass==true){

                       System.out.println("Passed");

               }

             else{

                   System.out.println("Fail");

               }

}

//Store the student's answers

private static String[] userAnswers;

//Process their answers

        public static void DriverExam (String[] Answers)

          {

                 userAnswers = new String[Answers.length];

                    for (int i = 0; i < Answers.length; i++)

                    {

                                  userAnswers[i] = Answers[i];

                        }

         }

//Check Whether Pass or fail

             public static boolean passed()

            {

                      if (totalCorrect() >= 15)

                                return true;

                      else

                               return false;

             }

//total Correct Answers

                 public static int totalCorrect()

                {

                          //student's answers

                          String[] correctAnswers =

                                                            {"B", "D", "A", "A", "C", "A",

                                                             "B", "A", "C", "D",

                                                              "B", "C", "D", "A",

                                                             "D", "C", "C", "B", "D", "A"};

                          int[] missed = new int[correctAnswers.length];

                          int correctCount = 0;

                           for (int i = 0; i < correctAnswers.length; i++)

                            {

                                       if (userAnswers[i].equalsIgnoreCase(correctAnswers[i]))

                                          {

                                                 correctCount++;

                                         }

                           }

                       return correctCount;

                 }

// total Incorrect Answers

          public static int totalIncorrect()

       {

                  String[] correctAnswers =

                                                        {"B", "D", "A", "A", "C", "A",

                                                         "B", "A", "C", "D",

                                                         "B", "C", "D", "A",

                                                           "D", "C", "C", "B", "D", "A"};

                int[] missed = new int[correctAnswers.length];

                int incorrectCount = 0;

               for (int i = 0; i < correctAnswers.length; i++)

              {

                            if (!userAnswers[i].equalsIgnoreCase(correctAnswers[i]))

                        {

                                missed[incorrectCount] = 1;

                                 incorrectCount++;

                        }

         }

          return incorrectCount;

}

}

//end of DriverExam class