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

Create a table named Quiz within a database called ExamDB. You should use the em

ID: 3931866 • Letter: C

Question

Create a table named Quiz within a database called ExamDB. You should use the embedded Java DB mode to implement this database.

Data is stored in a text file in the following csv format (questionNumber, description, choice1, choice2, choice3, choice4, Answer). Create your own csv text file containing quiz questions. Read from this file and store the records in the Quiz table within the ExamDB database.

Give the user a simple MCQ test from your Quiz table with 3 questions each time (one at a time and different each time), and print how many they got right and wrong.

For example

1,________ is the physical aspect of the computer that can be seen,a. Hardware,b. Software,c. Operating system,d.

Explanation / Answer

import java.util.Scanner;

class Quiz{

//Declare instance variables
String name[]=new String[100];
String answer[][]=new String[100][5];
String correctAnswers[]={“a”,”b”,”d”,”c”,”a”};
int i;

//Method to take user inputs
public void takeInputs(){

//Declare Variables
Scanner scan=new Scanner(System.in);
i=0;
int score=0;
String sentinel=””;

//Display Messages
System.out.println(“ Welcome to Java Quiz”);
System.out.println(“ You have 5 multiple choice questions.”);
System.out.println(“ Each question has 4 choices.”);
System.out.println(“ Enter the answer number as your answer”);
System.out.println(“ Each correct choice will fetch you 20 points”);

//Take inputs
System.out.print(“ Enter Your Name => “);
sentinel= scan.next();

while(!sentinel.equalsIgnoreCase(“xyz”)){

name[i]=sentinel;
//Question 1
System.out.print(“ 1.Another name for Class variable”);
System.out.println(“ (a) Static Variable”);
System.out.println(“(b) Instance Variables”);
System.out.println(“(c) Local Variables”);
System.out.println(“(d) None”);
System.out.print(“Enter Your Choice => “);
answer[i][0]=scan.next();
if(!(answer[i][0].equalsIgnoreCase(correctAnswers[0])))
System.out.println(“ Sorry! Correct answer is “+correctAnswers[0]);
else
{
System.out.println(“Correct!”);
score+=20;
}

//Question 2
System.out.println(“2.Memory allocation for char data type in bytes”);
System.out.println(“(a) 1 byte”);
System.out.println(“(b) 2 bytes”);
System.out.println(“(c) 3 bytes”);
System.out.println(“(d) 4 bytes”);
System.out.print(“Enter Your Choice => “);
answer[i][1]=scan.next();
if(!(answer[i][1].equalsIgnoreCase(correctAnswers[1])))
System.out.println(“ Sorry! Correct answer is “+correctAnswers[1]);
else
{
System.out.println(“Correct!”);
score+=20;
}

//Question 3
System.out.println(“3.Memory Allocation for boolean type array with dimension 5”);
System.out.println(“(a) 40 byte”);
System.out.println(“(b) 10 bytes”);
System.out.println(“(c) 20 bytes”);
System.out.println(“(d) 5 bytes”);
System.out.print(“Enter Your Choice => “);
answer[i][2]=scan.next();
if(!(answer[i][2].equalsIgnoreCase(correctAnswers[2])))
System.out.println(“ Sorry! Correct answer is “+correctAnswers[2]);
else
{
System.out.println(“Correct!”);
score+=20;
}

//Question 4
System.out.println(“4.Allowed Access Specifiers for a class”);
System.out.println(“(a) public and private”);
System.out.println(“(b) public, private and protected”);
System.out.println(“(c) public and default”);
System.out.println(“(d) public, private and default”);
System.out.print(“Enter Your Choice => “);
answer[i][3]=scan.next();
if(!(answer[i][3].equalsIgnoreCase(correctAnswers[3])))
System.out.println(“ Sorry! Correct answer is “+correctAnswers[3]);
else
{
System.out.println(“Correct!”);
score+=20;
}

//Question 5
System.out.println(“5.Wrapper Class for char data type”);
System.out.println(“(a) Character”);
System.out.println(“(b) character”);
System.out.println(“(c) char”);
System.out.println(“(d) Char”);
System.out.print(“Enter Your Choice => “);
answer[i][4]=scan.next();
if(!(answer[i][4].equalsIgnoreCase(correctAnswers[4])))
System.out.println(“ Sorry! Correct answer is “+correctAnswers[4]);
else
{
System.out.println(“Correct!”);
score+=20;
}
System.out.println(“ Your Total Score is “+score);
score=0;

i++;
if(i==100){
System.out.println(“ Sorry cannot make more entries. Limit exceeds”);
break;
}//if ends
else
{
System.out.println(“ Enter Student name/xyz to stop”);
sentinel=scan.next();
}//else ends
}//loop ends
}//method ends

//Calculate and display All Scores
public void calcScore(){
int j,k, score;

//Displaying headings
System.out.println(“ ALL SCORES”);
System.out.println(“Names Scores”);

for(j=0;j<i;j++){//for i no.of students
score=0;
for(k=0;k<5;k++){//for 5 answers of each student
if(answer[j][k].equalsIgnoreCase(correctAnswers[k]))
score+=20;
}//inner loop ends

//Print Score of Student
System .out.println(name[j]+” ”+score);

}//outer Loop ends
}//method ends
}//class ends

//class to test run the class ‘Quiz’
public class TestQuiz{
public static void main(String args[]){

Quiz obj=new Quiz(); //creating object of class Quiz
obj.takeInputs(); //call to method takeInputs()
obj.calcScore(); //call to method calcScores()
}//method ends
}//class ends

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