JAVA please follow all of the directions properly Also give


JAVA: please follow all of the directions properly. Also give the sample output with the copyable code. INDENt it according to instructions or it will have points reduced. Appreciate it , will leave you a thumbs up if all is done properly.
Thanks

Indentation instructions:

B. Write a program that grades the multiple choice drivers\' license exam. The exam has the following answer key 1. B A 9. C 10. D 11. B 12. C 13. D 14. A 15. D 16. C 17. C 18. B 19. D 20. A The program will input a person\'s answers and display the percent correct along with a message whether they passed or failed the test. Use the following methods: public static void getExamData (char responses that will let the user input the 20 values public static boolean passed (int num Correct) that returns true if they answer at least 15 out of the 20 correctly. public static int totalCorrect (char responses returns the number of correct answers using an array containing the answer key Turn in the following runs: 2) IBD AAC ABA CD BCD AD CCBDA 30 AABBABABAAAAAB AAAA AB

Solution

import java.util.*;
public class Exam{
  
    //initialize array to hold answers
    static char answers[]={\'B\',\'D\',\'A\',\'A\',\'C\',\'A\',\'B\',\'A\',\'C\',\'D\',\'B\',\'C\',\'D\',\'A\',\'D\',\'C\',\'C\',\'B\',\'D\',\'A\'};
    static final int size=20;
  
    //function which accepts the user for answers
    public static void getExamData(char responses[])
    {
        Scanner input=new Scanner(System.in);
        for(int i=0;i<size;i++)
        {
            System.out.print(\"Enter answer \"+ (i+1) +\": \");
            responses[i]=input.next().charAt(0);
        }
    }
  
    //function to calculate total correct answers provided by user
    public static int totalCorrect(char responses[])
    {
        int count=0;
        for(int i=0;i<size;i++)
        {
            if(responses[i]==answers[i])
            count++;
        }
        return count;
    }
  
    //function to check if the user is passed or failed
    public static boolean passed(int numCorrect)
    {
        if(numCorrect>14)
        return true;
        else
        return false;
    }

     public static void main(String []args){
         char responses[]=new char[20];
        getExamData(responses);
        int numCorrect=totalCorrect(responses);
        System.out.println(\"Your Percentage is: \"+(numCorrect*100)/size);
        if(passed(numCorrect))
        {
            System.out.println(\"Congratulations!! You have cleared the exam!!!\");
        }
        else
        {
            System.out.println(\"You have failed. Better luck next time.!!\");
        }
     }
}

Sample output:

Enter answer 1: A

Enter answer 2: A

Enter answer 3: A

Enter answer 4: A

Enter answer 5: A

Enter answer 6: A

Enter answer 7: A

Enter answer 8: A

Enter answer 9: A

Enter answer 10: A

Enter answer 11: A

Enter answer 12: A

Enter answer 13: A

Enter answer 14: A

Enter answer 15: A

Enter answer16: A                      

Enter answer 17: A

Enter answer 18: A

Enter answer 19: A

Enter answer 20: A                                                                                                                         

Your Percentage is: 30                                                                                                                                          

You have failed. Better luck next time.!!

 JAVA: please follow all of the directions properly. Also give the sample output with the copyable code. INDENt it according to instructions or it will have poi
 JAVA: please follow all of the directions properly. Also give the sample output with the copyable code. INDENt it according to instructions or it will have poi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site