Final Project Design a multiple choice quiz in java. No gui is needed. You shoul
ID: 3758563 • Letter: F
Question
Final Project
Design a multiple choice quiz in java. No gui is needed. You should use a buffer that inputs info to a file. You should ask 10 random questions in random order from a pool with X number of questions. These questions should be ranked/group specific. The user should be able to edit the questions,adding new questions, delete questions, edit the answers and define the groups. The quiz given to the user should read the file that you created. The questions asked should not have the number of the question, but instead the number of the question asked. The quiz should only ask one question at a time. If the user gets it right they move on and eventually pass. If they get it wrong they should start over in a new order. The quiz class should be genaric.
Hint: remember the write() we used in the previous lab.
For example the file could look like
Group A questions
Q1
A
B
C
D
Q2
A
B
C
D
Group B questions
..........
A quiz could look like :
Quiz 1
1. What is your name?//question is 10
A. Noname
B. Bob
C. Andrew
D. Emma
The test should use 5 groups with at 1 questions from each group. This means 5 quizes should be given.
You should submit the file and your code.
For extra credit:
Seperately in another file modify your code to use sql.
Explanation / Answer
import java.util.Scanner;
import java.lang.String;
/**
* MultipleChoiceQuiz question 3 Assignment 2.
*
* @author bresker
* @version 1.0
*/
public class StuartsMultipleChoiceQuiz
{
/**
* This method simply prints the user's input to the console.
*
*/
public static void printResults(String userInput[]){
System.out.println(" Question No. User Input");
for (int i = 0; i < userInput.length; i++){
System.out.println((i + 1) + ". " + userInput[i]);
} // end for
} // end of method printResults(...)
/**
* This overloaded method prints the correct answers and the
* user's input to the console.
*
*/
public static void printResults(String correctAnswers[], String userInput[]){
System.out.println("Question No. Correct answer User Input");
for (int i = 0; i < correctAnswers.length; i++){
System.out.println((i + 1) + ". " + correctAnswers[i] + " " + userInput[i]);
} // end for
} // end of method printResults(...)
/**
* This overloaded method prints the correct answers, the
* user's input and the number of questions answered correctly
* to the console.
*
*/
public static void printResults(String correctAnswers[], String userInput[], int numberCorrectAnswers){
System.out.println(" Question No. Correct answer User Input");
for (int i = 0; i < correctAnswers.length; i++){
System.out.println((i + 1) + ". " + correctAnswers[i] + " " + userInput[i]);
} // end for
System.out.println(" Number of questions answered correctly: " + numberCorrectAnswers);
} // end of method printResults(...)
/**
* This method calculates the number of correct answers inputted by
* the user and returns it to the calling method.
*
*/
public static int compareResults(String correctAnswers[], String userInput[]){
int numberCorrectAnswers = 0;
for(int i = 0; i < correctAnswers.length; i++){
if (correctAnswers[i].equals(userInput[i])){
numberCorrectAnswers++;
} // end if
} // end for loop
return (numberCorrectAnswers);
} // end compare results
public static void main(String args[]){
final String correctAnswers[] = new String[10];
correctAnswers[0] = "A";
correctAnswers[1] = "D";
correctAnswers[2] = "B";
correctAnswers[3] = "C";
correctAnswers[4] = "D";
correctAnswers[5] = "C";
correctAnswers[6] = "B";
correctAnswers[7] = "A";
correctAnswers[8] = "D";
correctAnswers[9] = "A";
Scanner myScanner = new Scanner(System.in);
String userInput[] = new String[10];
final String questions[] = new String[10];
questions[0] = "What is the capital of Australia? ------- A - Canberra B - Sydney C - Perth D - Kangaroo Island ";
questions[1] = "What is a Dugong? ------- A - A bird B - A boat C - A ghost D - A sea creature ";
questions[2] = "How many inches in a foot? ------- A - 24 B - 12 C - 36 D - A million and one ";
questions[3] = "How many metres in a mile? ------- A - 2040m B - 1212m C - 1609m D - The House of Commons ";
questions[4] = "The Latin name for which creature is 'pica pica'? ------- A - The Hippogriff B - The blackbird C - The Jay D - The Magpie ";
questions[5] = "Which Roman emperor made his horse a senatorial consul? ------- A - Augustus B - Constantine C - Caligula D - Nero ";
questions[6] = "What is the main ingredient of Lava Bread? ------- A - Nettles B - Seaweed C - Bran D - Moss ";
questions[7] = "What is the largest state in the US of A? ------- A - Alaska B - Colorado C - Texas D - Hawaii ";
questions[8] = "Where would you find the scapula bone? ------- A - Thigh B - Knee C - Chest D - Shoulder ";
questions[9] = "What was the UK Christmas Number 1 in 1975? ------- A - Bohemian Rhapsody B - Mary's Boy Child C - Merry Xmas Everybody D - Lonely this Christmas ";
System.out.println("Welcome to the multiple choice quiz... ");
System.out.println("Please select a response from A to D.. ");
for (int i = 0; i < 10; i++){
System.out.print(" Please enter answer to question " + (i + 1) + " >> " + questions[i]);
userInput[i] = myScanner.nextLine();
userInput[i] = userInput[i].toUpperCase();
// Perform some error checking here
if
(userInput[i].equals("A") || userInput[i].equals("B") || userInput[i].equals("C") || userInput[i].equals("D"));
// Do nothing;
else userInput[i] = "X";
} // end for
// printResults(userInput);
// printResults(correctAnswers, userInput);
int numberCorrectAnswers = compareResults(correctAnswers, userInput);
int numberIncorrectAnswers = (10 - numberCorrectAnswers);
printResults(correctAnswers, userInput, numberCorrectAnswers);
System.out.println(" You got " + numberIncorrectAnswers + " answers incorrect.");
System.out.println(" The pass mark is seven correct answers");
if (numberCorrectAnswers >6)
{ System.out.println(" Well, done you passed my quiz. You are a STUART'S QUIZ legend.");
}
else
{
System.out.println(" Sorry, you have failed my quiz. You are a STUART'S QUIZ turkey.");
}
} // end main
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.