Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class called ComputerTest. The ComputerTest class should have the follo

ID: 3564066 • Letter: C

Question

Create a class called ComputerTest. The ComputerTest class should have the following private fields:

A private String called name that stores the name of the test, i.e. Final Exam

A private array of characters that stores the correct answers for a multiple choice exam. For example, the correct answers may be:A, C, D, C, B, A, A, C, C, B

A private array of characters that stores the answers given on the exam.

The ComputerTest class should have the following methods:

A no-arg constructor that builds a ComputerTest object with no answers.

An overloaded constructor that assigns the answers.

Accessor and mutator methods for each of the private fields.

A method called getGrade that compares the answers given to the correct answers and returns the percent correct.

A method called getWrong that returns an array of integers that stores the question numbers that were answered correctly.

A method called getNumberCorrect that returns the number of questions that were answered correctly

Demonstrate the class in a tester program that uses all the methods. Include appropriate JavaDoc comments.

Explanation / Answer


public class ComputerTest
{
private String name="Final Test"; //Name of the test
private char[] correct={'A','C','D','C','B','A','A','C','C','B'}; // Correct answers
private char[] attempt; // stores answers attempted by the user.

public ComputerTest(){ // default constructor.
}
public ComputerTest(char[] ch) // parameterized constructor.
{
attempt=new char[correct.length]; // storing the answers attempted by user.
for (int i = 0; i < correct.length; i++) {
attempt[i]=ch[i];
}
}
  
public String accessor()
{ // returns the name of the exam.
return name;
}
public String mutator()
{ // returns all correct answers.
String str="";
for (int i = 0; i < correct.length; i++) {
str=str+correct[i]+" ";
}
return str;
}
public double getGrade()
{
int k=0;
for (int i = 0; i < correct.length; i++) { // counting number of correct answers in k.
if(attempt[i]==correct[i]) k++;
}
return (100.0*k/correct.length); // returning the percentage.
}
public int getWrong()
{
int k=0;
for (int i = 0; i < correct.length; i++) {
if(attempt[i]==correct[i]) k++;
} // counting the number of correct answers in k.
return correct.length-k;// return number of wrong answers.
}
public int getNumberCorrect()
{
int k=0;
for (int i = 0; i < correct.length; i++) {
if(attempt[i]==correct[i]) k++;
}
return k; // returning number of correct answers.
}
  
}


public class Tester
{
public static void main(String[] args)
{
char[] ch={'B','C','A','C','A','B','A','D','A','B'};
ComputerTest test=new ComputerTest(ch);
System.out.println("Name of Exam: "+test.accessor());
System.out.println("Correct answers:"+test.mutator());
System.out.println("Grade in percentage: "+test.getGrade()+" %");
System.out.println("Number of correct answers: "+test.getNumberCorrect());
System.out.println("Number of wrong answers: "+test.getWrong());
}
}

OUTPUT:

run:
Name of Exam: Final Test
Correct answers:A C D C B A A C C B
Grade in percentage: 40.0%
Number of correct answers: 4
Number of wrong answers: 6
BUILD SUCCESSFUL (total time: 0 seconds)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote