mercredi 20 octobre 2021

JAVA , How to acumulate every wrong answer that has been subtracted by specific number [closed]

Assuming that 1 mark is given to a correct answer and 0.25 marks is subtracted for each wrong answer: how do i accumulate wrong answer that has subtracted by 0.25 ?

The output number marks should be like this:

Student 1: 6.25 Student 2: 5.00 Student 3: 3.75 Student 4: 2.50 Student 5: 7.50 Student 6: 6.25 Student 7: 6.25 Student 8: 6.25 Student 9: 8.75

public class Q3 {
    public static void main (String[] args) {
    
      char answer[][] =
  {
          {'A','B','A','C','C','D','E','E','A','D'},
          {'D','B','A','B','C','A','E','E','A','D'},
          {'E','D','D','A','C','B','E','E','A','D'},
          {'C','B','A','E','D','C','E','E','A','D'},
          {'A','B','D','C','C','D','E','E','A','D'},
          {'B','B','E','C','C','D','E','E','A','D'},
          {'B','B','A','C','C','D','E','E','A','D'},
          {'E','B','E','C','C','D','E','E','A','D'}
  };
 
  char keys[] = {'D','B','D','C','C','D','A','E','A','D'};
  double[] student = new double[answer.length];
  for(int i = 0; i < answer.length; ++i)
  {
      double right = 0;
      for(int j = 0; j < answer[i].length; ++j)
      {
          if(answer[i][j] == keys[j]) 
              ++right;         
      }
      
      double wrong = 0;
      for(int j = 0; j < answer[i].length; ++j)
      {
          if(answer[i][j] == keys[j]) 
              ++wrong;         
      }
      student[i] = right + wrong;   // right  - wrong
  }

  for(int i = 0; i < student.length; ++i)
      System.out.println("student"+(i+1)+ " " + student[i]);
}
}

Aucun commentaire:

Enregistrer un commentaire