navinreddy20 / quiz-app-spring

34 stars 61 forks source link

Update QuizService.java #2

Open Kuldeep4498 opened 11 months ago

Kuldeep4498 commented 11 months ago

Changed calculateResult() method to calculate result in quizService.

Issue: Previous method only worked if response list and questions list were in same order. What if response is suffled or list of questions fetched from database is not in order of respose then there answers won't match as we are matching them with index, not by id.

Solution: Created a HashMap to store key as 'id' and value as 'question' object and store all questions in Map.

Now it became easy to fetch question by "response.getId" and compared both answers.

Now it will give right answer every time doesn't matter what is the sequence of lists.

Kuldeep4498 commented 11 months ago

Hi Navin,

Please review my changes....I think It workes better then previous one and is more accurate.

Thanks, Kuldeep