Code instructions Indentations instruction Plz Avoid these m


Code instructions:


Indentations instruction;

Plz Avoid these mistakes or ill lose points:

Solution

Please follow the code and comments for description :

CODE :

import java.util.Scanner; // REQUIRED IMPORTS

public class LicenseExamResults { // class used to run the code

    public static void getExamData() { // method that will let the user input the 20 responses

        char responses[] = new char[20]; // local array of characters to save the resposnes of the user
        int numCorrect = totalCorrect(responses); // call the method to get the total responses that are correct by passing the arrays as a parameter
        boolean resFlag = passed(numCorrect); // check the result for the responses given by passing the total correct responses
        if (resFlag == true) { // check for the flag value
            System.out.println(\"You Cleared the Exam.!\ Congratulations.!!!\"); // message to the user
        } else {
            System.out.println(\"Sorry, You Falied.\ Try Your Luck Next Time.\"); // message to the user
        }

    }

    public static boolean passed(int numCorrect) { // method that takes in the count of correct resposnes and send the result

        double percent;
        if (numCorrect >= 15) { // check for the count of repsonses that are correct
            percent = (numCorrect / 20) * 100; // calculate the percentage
            System.out.println(\"The Correct Percentage is : \" + percent + \"%\");
            return true;
        } else {
            percent = (numCorrect / 20) * 100;
            System.out.println(\"The Correct Percentage is : \" + percent + \"%\");
            return false;
        }
    }

    public static int totalCorrect(char responses[]) { // method that takes in the array as a parameter to check for the correct values

        Scanner sc = new Scanner(System.in); // scanner class to get the data from the user
        int count = 0; // local variable
        char examKey[] = \"BDAACABACDBCDADCCBDA\".toCharArray(); // key for the exam

        System.out.println(\"Please Enter your Responses : \"); // prompt for the user
        for (int i = 0; i < responses.length; i++) { // get the data
            System.out.println(\"Enter the Response \" + (i + 1) + \" : \");
            char c = sc.next().charAt(0); // read the data
            responses[i] = c; // save to the array
        }

        for (int j = 0; j < 20; j++) {
            if (examKey[j] == responses[j]) { // check for the responses with the key
                count++; // increment the count
            }
        }
        return count; // return the count
    }

    public static void main(String[] args) { // driver method

        System.out.println(\"Welcome to the Driver\'s License Exam Results Calculator.!\"); // message about the code
        getExamData(); // call the method
    }
}

OUTPUT :

Case 1 :

Welcome to the Driver\'s License Exam Results Calculator.!
Please Enter your Responses :
Enter the Response 1 :
B
Enter the Response 2 :
D
Enter the Response 3 :
A
Enter the Response 4 :
A
Enter the Response 5 :
C
Enter the Response 6 :
A
Enter the Response 7 :
B
Enter the Response 8 :
A
Enter the Response 9 :
C
Enter the Response 10 :
D
Enter the Response 11 :
B
Enter the Response 12 :
C
Enter the Response 13 :
D
Enter the Response 14 :
A
Enter the Response 15 :
D
Enter the Response 16 :
C
Enter the Response 17 :
C
Enter the Response 18 :
A
Enter the Response 19 :
D
Enter the Response 20 :
B
The Correct Percentage is : 90.0%
You Cleared the Exam.!
Congratulations.!!!

Case 2 :

Welcome to the Driver\'s License Exam Results Calculator.!
Please Enter your Responses :
Enter the Response 1 :
C
Enter the Response 2 :
A
Enter the Response 3 :
B
Enter the Response 4 :
A
Enter the Response 5 :
C
Enter the Response 6 :
D
Enter the Response 7 :
B
Enter the Response 8 :
A
Enter the Response 9 :
A
Enter the Response 10 :
B
Enter the Response 11 :
C
Enter the Response 12 :
D
Enter the Response 13 :
A
Enter the Response 14 :
D
Enter the Response 15 :
C
Enter the Response 16 :
C
Enter the Response 17 :
D
Enter the Response 18 :
B
Enter the Response 19 :
A
Enter the Response 20 :
A
The Correct Percentage is : 35.0%
Sorry, You Falied.
Try Your Luck Next Time.


Hope this is helpful.

 Code instructions: Indentations instruction; Plz Avoid these mistakes or ill lose points:SolutionPlease follow the code and comments for description : CODE : i
 Code instructions: Indentations instruction; Plz Avoid these mistakes or ill lose points:SolutionPlease follow the code and comments for description : CODE : i
 Code instructions: Indentations instruction; Plz Avoid these mistakes or ill lose points:SolutionPlease follow the code and comments for description : CODE : i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site