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

A java question Question 2: Cheating in Exams (45 points) For this question, you

ID: 3862357 • Letter: A

Question

A java question

Question 2: Cheating in Exams (45 points) For this question, you will again use multi-dimensional arrays, and you will write several methods to build a program that flags students for potential cheating on multiple choice exams. Your code for this question should go in the same file as the previous question ExamGrading.java Page 3 (a) Write a method numWrongSimilar that takes as input two char arrays representing the answers of two different students, as well as a char array of solutions. This method returns the number of wrong answers that the students had the same. This method should throw an IllegalArgumentException if the students have responses that differ in length from each-other, or from the solutions. For example, suppose the answer arrays are 'A', 'B', 'C', 'D', 'C', 'A' 'A', 'B', 'D', 'B', 'B', 'A' and the solutions are 'C', 'B', 'C', 'D', 'A', 'A' Then the method would return 1, since the only question where they both put the same wrong answer is the first one.

Explanation / Answer

Please see below the Answer.


public class ExamGrading {
  
  


   /**
   * Method to return the count of same wrong answers for two different students
   * @param answer1
   * @param answer2
   * @param solution
   * @return int
   */
   public int numWrongSimilar(char[] answer1, char[] answer2, char[] solution){
       int sameWrongCount = 0;
       for(int i=0;i<solution.length ; i++){
           if(solution[i]!= answer1[i]){ //Checking the wrong answer
               if(answer1[i] == answer2[i] ){ //Checking the wrong answers are similar
                   //Incrementing the count
                   sameWrongCount ++;
               }
           }
       }
       return sameWrongCount;
   }

   /**
   * Returns the number of students who shares wrong answers with the student at index
   * @param response
   * @param solution
   * @param index
   * @param similarThreshold
   * @return int
   */
   public int numMatches(char[][] response,char[] solution, int index, int similarThreshold){
       char[] currentStudentAnswer = response[index];
       int countStudent = 0;
       for(int i=0; i<response.length ; i++){
           if(i != index){
               int countWrong = numWrongSimilar(currentStudentAnswer, response[i], solution);
               if(countWrong >= similarThreshold){
                   countStudent ++;
               }
           }
       }

       return countStudent;

   }
/***
*
*
* @param minNoAnswers
* @param response
* @param solution
* @return
*/
   public int[][] findSimilarAnswers(int minNoAnswers, char[][] response, char[] solution){
       int[][] similarAnswers = new int[response.length][response.length-1];
       int[] indices = new int[response.length-1];
       int counter =0;
       for(int i=0; i<response.length ; i++){
           for(int j=0; j<response.length; j++){
               if(i!=j){
                   int countWrong = numWrongSimilar(response[i], response[j], solution);
                   if(countWrong >= minNoAnswers){
                       indices[counter] = j;
                       counter++;
                   }
               }
              
           }
          
           similarAnswers[i] = indices;

       }

       return similarAnswers;
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote