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.
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.!!

