Develop a program Using Java language on netbeans) and write the entire code for
ID: 3823494 • Letter: D
Question
Develop a program Using Java language on netbeans) and write the entire code for this game. Driving test game is a game that is based about asking the user 10 MCQ questions about driving and it has at the bottom graphical car, which will move whenever user answers correctly. This project has 3 Classes 1- main class it will contain the text fields to enter information about the user and it contains a JButton called "start" when this button pressed it should open new frame called ("questions") 2- in questions class the new frame should contain JtextArea not editable and contain the questions once the user selects the answer from RadioButtons and click on submit button and if the answer isExplanation / Answer
public class DriverTEST
{
//An array containing a student's answers
private String[] correctAnswers =
{"B", "D", "A", "A", "C", "A",
"B", "A", "C", "D",
"B", "C", "D", "A",
"D", "C", "C", "B", "D", "A"};
//Store the user's answers
private String[] userAnswers;
int[] missed = new int[correctAnswers.length];
//Process the user's answers
public DriverTEST (String[] Answers)
{
userAnswers = new String[Answers.length];
for (int i = 0; i < Answers.length; i++)
{
userAnswers[i] = Answers[i];
}
}
//Returns a boolean value if correct answers > 15
public boolean passed()
{
if (totalCorrect() >= 15)
return true;
else
return false;
}
//Determines the total correct answers
public int totalCorrect()
{
int correctCount = 0;
for (int i = 0; i < correctAnswers.length; i++)
{
if (userAnswers[i].equalsIgnoreCase(correctAnswers[i]))
{
correctCount++;
}
}
return correctCount;
}
//Determines the total incorrect answers
public int totalIncorrect()
{
int incorrectCount = 0;
for (int i = 0; i < correctAnswers.length; i++)
{
if (!userAnswers[i].equalsIgnoreCase(correctAnswers[i]))
{
missed[incorrectCount] = i;
incorrectCount++;
}
}
return incorrectCount;
}
//Missed questions
public int[] questionsMissed()
{
return missed;
}
}
//end of DriverTEST class
----------------------------------------------------------------------------
import java.util.Scanner;
public class DriverTESTApplication
{
public static void main(String[] args)
{
System.out.println(" Driver's License TEST ");
Scanner input = new Scanner(System.in);
System.out.println(" 20 Multiple-Choice Questions ");
System.out.println(" Mark A, B, C, D ");
//Inputting string
String[] answers = new String[20];
String answer;
for (int i = 0; i < 20; i++)
{
do
{
System.out.print((i+1) + ": ");
answer = input.nextLine();
} while (!isValidAnswer(answer));
answers[i] = answer;
}
//Process
DriverTEST test = new DriverTEST(answers);
//Results
System.out.println(" RESULTS ");
//Outputting total correct
System.out.println("Total Correct: " + test.totalCorrect());
//Outputting total incorrect
System.out.println("Total Incorrect: " + test.totalIncorrect());
String passed = test.passed() ? "YES" : "NO";
//Result pass or fail
System.out.println("Passed: " + passed);
if (exam.totalIncorrect() > 0)
{
System.out.println("The incorrect answers are: ");
int missedIndex;
for (int i = 0; i < test.totalIncorrect(); i++)
{
missedIndex = test.questionsMissed()[i]+1;
System.out.print(" " + missedIndex);
}
}
} //end of main function
//Returns true when answer is valid
public static boolean isValidAnswer (String answer)
{
return "A".equalsIgnoreCase(answer) ||
"B".equalsIgnoreCase(answer)
|| "C".equalsIgnoreCase(answer) ||
"D".equalsIgnoreCase(answer);
}
} //end of Test class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.