Question: Java language only **Mandatory Rules** Put Descriptive comments on the code displayed on top of previous comments alreadys displayed On Top of Code write summary

Java language only

**Mandatory Rules**

Put Descriptive comments on the code displayed on top of previous comments alreadys displayed

On Top of Code write summary of what code will do in comments

At the end of the code have the output in comment form

**indent the code for good coding syle* its not orginized now please fix it*

I Will thumbs up good Work thanks

import java.io.*; public class DriverExam { final char answers[] = {'B','D','A','A','C','A','B','A','C','D','B','C','D','A','D','C','C','B','D','A'}; //Assigned answers array boolean passed(char input[]) { int correct=0,i;//Variable declaratoion for(i=0;i<20;i++)//Looping for 20 times { if(input[i]==answers[i])//Matches input answers to the actual answers correct++; } if(correct>=15)//Pass Condition. Returns true if false else fail return true; else return false; } int totalCorrect(char input[])//Calculates and returns total correct answers { int correct=0,i; for(i=0;i<20;i++)//Loop 20 times { if(input[i]==answers[i])//Matches input answers to the actual answers correct++;//If match found increment correct answers count } return correct; } int totalIncorrect(char input[]) { int incorrect=0,i; for(i=0;i<20;i++) { if(input[i]!=answers[i]) incorrect++; } return incorrect; } int[] questionMissed(char input[])//Find the questions incorrectly answered { int missed[]=new int[20]; int cnt=0,i; for(i=0;i<20;i++)//Initialize all elements of missed to -1 { missed[i]=-1; } for(i=0;i<20;i++)//Loop 20 times { if(input[i]!=answers[i])//Matches input answers to the actual answers { missed[cnt]=i+1;//If match not found store question number in array. Remember question number is always 1 more than index(variable i) as 'i' starts from 0 but question nos start from 1. cnt++; } } return missed; } public static void main(String[] args)throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in));//Alternatively use scanner class for user input DriverExam ob = new DriverExam();//Object Creation int i,correct,incorrect;int missed[]; char input[] = new char[20];boolean result; System.out.println("Enter Answers: ");//Accept user answers for(i=0;i<20;i++) { do { System.out.print("Q."+(i+1)+": "); input[i]=(in.readLine()).charAt(0); if(input[i]!='A' && input[i]!='B' && input[i]!='C' && input[i]!='D')//InputValidation { System.out.println("Invalid Answer. Enter a valid Answer."); } }while(input[i]!='A' && input[i]!='B' && input[i]!='C' && input[i]!='D'); } //Function calls result = ob.passed(input); correct = ob.totalCorrect(input); incorrect = ob.totalIncorrect(input); missed = ob.questionMissed(input); //Display Results if(result == true) System.out.println("Result: Passed"); else System.out.println("Result: Failed"); System.out.println("No of Correct Answers: "+correct); System.out.println("No of InCorrect Answers: "+incorrect); if(missed[0]==-1) { System.out.print("Questions Missed: NA"); } else { System.out.print("Questions Missed: "+missed[0]); i=1; while(missed[i]!=-1) { System.out.print(", "+missed[i]); i++; } } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!