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

Don\'t forget the Illegalargumentexception part in question1 Question 1: Exam Gr

ID: 3803101 • Letter: D

Question

Don't forget the Illegalargumentexception part in question1

Question 1: Exam Grading (15 points) For this question, you will use multi-dimensional arrays to write a program that grades a multiple choice exam. Your code for this question should go in a file ExamGrading.java We strongly recommend that you complete the first three warm-up questions before start- ing this problem. Write a method gradeAllStudents that takes as input a two dimensional char array containing student responses to a multiple choice exam, and a one dimensional char array containing the solutions to each question. Each element in the 2d array is an array representing one student's responses to the entire exam. This method returns a double CJ representing the grades for each student as percentages. Assume that all questions are worth 1 point. You may also assume that all char values are upper-case letters, and valid exam responses If, at any point, the number of responses for a student does not match the number of questions on the exam (the number of solutions), your method should throw an IllegalArgumentException that contains a message letting the user know which student (by index) caused the error, as well as what the two conflicting lengths were. Below is an example. Suppose we have a multiple choice exam with 6 questions and written by 4 students char CJ Cl responses H'C', 'A', 'B', 'B', 'C', 'A't, t'A', 'A', 'B' 'B', 'B', 'B' H'C', 'B', 'A' 'B', 'C', 'A21, 'A', 'B', 'A', 'B 'B', 'B' th; char L solutions C', 'A', 'B', 'B', 'C', 'C' The output of gradeAllStudents would look like: 183.33333333333334, 50.0, 50.0, 16.666666666666664

Explanation / Answer

package org.jay.chegg;

class ExamGrading{
  
   public static final int noOfQuestions=6;

  
   /**
   *
   * @param responses
   * @param solutions
   * @return the grades of all the students
   */
   public double[] gradeAllStudents(char[][]responses,char[]solutions){
       double [] grades=new double[4];
       for(int i=0;i<responses.length;i++){
           if(responses[i].length!=noOfQuestions){
               int index=i+1;
               throw new IllegalArgumentException("Student "+index+" answers are causing the error"); // throwing exception if responses exceeds 6
           }
           int correctAnswers=0;
           for(int j=0;j<responses[i].length;j++){
               if(responses[i][j]==solutions[j]){
                   correctAnswers++; // increasing the correct answer
               }
           }
           double grade=((double)correctAnswers/(double)solutions.length)*100; //calculates the grade
           grades[i]=grade; // saving the grade into array
       }
      
       return grades;
   }
  
   /**
   *
   * @param responseA
   * @param responseB
   * @param solutions
   * @return similar wrong answer count
   */
   public int numWrongSimilar(char[]responseA,char[]responseB,char[]solutions){
       int similarCount=0;
       if(responseA.length!=noOfQuestions){
           throw new IllegalArgumentException("This Student A answers are causing the error"); // throwing exception if responses exceeds 6
       }
       if(responseB.length!=noOfQuestions){
           throw new IllegalArgumentException("This Student B answers are causing the error"); // throwing exception if responses exceeds 6
       }
      
       for(int j=0;j<solutions.length;j++){
           if(responseA[j]!=solutions[j]){
               if(responseB[j]!=solutions[j]){
                   if(responseB[j]==responseA[j]){
                       similarCount++;
                   }
               }
           }
       }
       return similarCount;
   }
  
  
   /**
   *
   * @param responses
   * @param solutions
   * @param index
   * @param threshold
   * @return num matches greater than equal to threshold
   */
   public int numMatches(char[][]responses,char[]solutions,int index,int threshold){
       int numMatch=0;
       char[]studentWithIndex=responses[index];
       for(int i=0;i<responses.length;i++){
           if(i!=index){
               int sameWrongAnswer=0;
               sameWrongAnswer=numWrongSimilar(responses[i],studentWithIndex,solutions);//calling the samewronganswer method to found the similarity
               if(sameWrongAnswer>=threshold){
                   numMatch++;
               }
           }
       }
       return numMatch;
   }
  

  
  
}

public class ExamGradingDemo {

   public static void main(String[] args) {
       char [][]responses={{'C','A','B','B','C','A'},{'A','A','B','B','B','B'},{'C','B','A','B','C','A'},{'A','B','A','B','B','B'}};
       char[]solutions={'C','A','B','B','C','C'};
       ExamGrading grading=new ExamGrading();
       double[]grades=grading.gradeAllStudents(responses, solutions);
       System.out.println(grades);
       char[]responseA={'A','B','C','D','C','A'};
       char[]responseB={'A','B','D','B','B','A'};
       char[]solutions2={'C','B','C','D','A','A'};
       int count = grading.numWrongSimilar(responseA, responseB, solutions2);
       System.out.println("Similar wrong answer count is "+count);
      
       char[][]responses2={{'A','B','C','D','B','A'},{'C','B','D','D','B','B'},{'C','B','D','D','C','B'}};
      
       char[]solutions3={'C','B','C','D','A','A'};
       int match=grading.numMatches(responses2, solutions3, 1, 2);
       System.out.println("Num matches : "+match);
      
   }

}

----------------------------------------------------------------output--------------------------------------------------------------------------

[83.33333333333334, 50.0, 50.0, 16.666666666666664]
Similar wrong answer count is 1
Num matches : 1

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