Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: ISC COMPUTER SCIENCE PRACTICAL 2017 QUESTION 2

Tuesday, March 12, 2019

ISC COMPUTER SCIENCE PRACTICAL 2017 QUESTION 2




import java.util.*;
public class ISC2017Q2 {
       public static void main(String[] args) {
             int N;
             Scanner in = new Scanner(System.in);
             System.out.println("Enter the number of participants:");
             N = in.nextInt();
             while( N <=3 || N >=11) {
                    System.out.println("Invalid input, try again:");
                    N = in.nextInt();
             }
             Match obj = new Match(N);
             System.out.println("Enter the answer key:");
             obj.getAnswerKey();
             System.out.println("Enter the participants answer:");
             System.out.println();
             obj.getParticipantAnswer();
             System.out.println("OUTPUT:N = "+N);
             obj.calculateScores();
             System.out.println();
             obj.display();
             in.close();
       }
}
class Match {
public void display() {
       System.out.println("SCORES:");
       for(int i=0;i<no_of_candidates;i++) {
             System.out.println("PARTICIPANT "+(i+1)+" ="+participant_scores[i]);
             if(highest_score<participant_scores[i])
                    highest_score = participant_scores[i];
                    }
       System.out.println("Highest Score:");
       for(int j=0;j<no_of_candidates;j++) {
             if(highest_score==participant_scores[j])
                    System.out.println("PARTICIPANT "+(j+1)+" with score"+participant_scores[j]);
             }
       }
      
public void calculateScores() {
       char[] temp;
       for(int i=0;i<no_of_candidates;i++) {
             participant_scores[i]=0;
             temp = participant_answers[i].toCharArray();
             System.out.print("PARTICIPANT "+(i+1));
             for(int j=0;j<5;j++) {
                    System.out.print(" "+temp[j]+" ");
                    if(temp[j]==answer_key[j])
                          participant_scores[i]++;
             }
             System.out.println();
       }
       }
public void getParticipantAnswer() {
       Scanner in = new Scanner(System.in);
       for(int i=0;i<no_of_candidates;i++) {
             System.out.println("Enter the answer for Participant:"+(i+1));
             participant_answers[i]=in.nextLine();
             }
       }
public void getAnswerKey() {
       String temp;
       Scanner in = new Scanner(System.in);
       temp = in.nextLine();
       answer_key = temp.toCharArray(); // using library function- converting string to char array
       }
Match(int N){
       no_of_candidates = N;
       highest_score = 0;
       participant_scores = new int[no_of_candidates];
       answer_key = new char[no_of_candidates];
       participant_answers = new String[no_of_candidates];
       }
       private int highest_score;
       private int no_of_candidates;
       private int[] participant_scores;
       private String[] participant_answers;
       private char[] answer_key;
}              

2 comments:

  1. Thank you so much. It was indeed helpful.

    ReplyDelete
    Replies
    1. If you are in grade XII, kindly mail me at maths.programming@gmail.com

      Delete