Question

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

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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(“\t\t\tWelcome to Java Quiz”);
System.out.println(“\n\tYou have 5 multiple choice questions.”);
System.out.println(“\tEach question has 4 choices.”);
System.out.println(“\tEnter the answer number as your answer”);
System.out.println(“\tEach correct choice will fetch you 20 points”);

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

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

name[i]=sentinel;
//Question 1
System.out.print(“\n1.Another name for Class variable”);
System.out.println(“\n(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(“\nSorry! 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(“\nSorry! 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(“\nSorry! 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(“\nSorry! 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(“\nSorry! Correct answer is “+correctAnswers[4]);
else
{
System.out.println(“Correct!”);
score+=20;
}
System.out.println(“\nYour Total Score is “+score);
score=0;

i++;
if(i==100){
System.out.println(“\nSorry cannot make more entries. Limit exceeds”);
break;
}//if ends
else
{
System.out.println(“\nEnter 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(“\nALL SCORES”);
System.out.println(“Names\t\t\tScores”);

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]+”\t\t\t”+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

Add a comment
Know the answer?
Add Answer to:
Create a table named Quiz within a database called ExamDB. You should use the embedded Java...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • see below: You will be creating a personal quiz that will provide a grade depending on the responses given. The quiz should contain at least three questions of the true/false or multiple-choice natu...

    see below: You will be creating a personal quiz that will provide a grade depending on the responses given. The quiz should contain at least three questions of the true/false or multiple-choice nature. You should select only one type of question to use. These questions should originate from Comprehension Check in your textbook (noting the chapter and page number) These questions and the correct answer identifier should be stored in a text file. A second table should contain the possible...

  • This should be in Java Create a simple hash table You should use an array for...

    This should be in Java Create a simple hash table You should use an array for the hash table, start with a size of 5 and when you get to 80% capacity double the size of your array each time. You should create a class to hold the data, which will be a key, value pair You should use an integer for you key, and a String for your value. For this lab assignment, we will keep it simple Use...

  • Overview: Database management plays an integral role in nearly every area of business. Databases house customer, accoun...

    Overview: Database management plays an integral role in nearly every area of business. Databases house customer, accounting, and employee data, and these different data sets must all be efficiently managed in order to make the data accessible. Companies rely on database engineers to ensure that their records are accurate, updated, and tracked in real time. This course covers structured query language (SQL) and how it can be used to manage database schemas, manipulate data, and analyze data. For your final...

  • !!!!!!!Java!!!!! When you are confident that your methods work properly and that you can generate random...

    !!!!!!!Java!!!!! When you are confident that your methods work properly and that you can generate random text with my generateText method, you can move on to the second step. Create a third class called Generator within the cs1410 package. Make class. This class should have a main method that provides a user interface for random text generation. Your interface should work as follows: Main should bring up an input dialog with which the user can enter the desired analysis level...

  • Mini Case Building Shared Services at RR Communications4 4 Smith, H. A., and J. D. McKeen....

    Mini Case Building Shared Services at RR Communications4 4 Smith, H. A., and J. D. McKeen. “Shared Services at RR Communications.” #1-L07-1-002, Queen’s School of Business, September 2007. Reproduced by permission of Queen’s University, School of Business, Kingston, Ontario, Canada. Vince Patton had been waiting years for this day. He pulled the papers together in front of him and scanned the small conference room. “You’re fired,” he said to the four divisional CIOs sitting at the table. They looked nervously...

  • Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin...

    Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin at the University of Washington, Seattle, who originally wrote this assignment (for their CSE 142, in Java) This program focuses on classes and objects. Turn in two files named Birthday.cs and Date.cs. You will also need the support file Date.dll; it is contained in the starter project for this assignment. The assignment has two parts: a client program that uses Date objects, and a...

  • Mini Case Building Shared Services at RR Communications4 4 Smith, H. A., and J. D. McKeen....

    Mini Case Building Shared Services at RR Communications4 4 Smith, H. A., and J. D. McKeen. “Shared Services at RR Communications.” #1-L07-1-002, Queen’s School of Business, September 2007. Reproduced by permission of Queen’s University, School of Business, Kingston, Ontario, Canada. Vince Patton had been waiting years for this day. He pulled the papers together in front of him and scanned the small conference room. “You’re fired,” he said to the four divisional CIOs sitting at the table. They looked nervously...

  • internal project 1 anything helps! thank you!! Instructions: Study the case that starts on page 3...

    internal project 1 anything helps! thank you!! Instructions: Study the case that starts on page 3 carefully. Then write concise answers to the following questions regarding the internal control system of Duarf, Inc. Clearly label your responses with proper headings and subheadings. Be very specific and precise. Answers that appear to be beating around the bush will not get any credit. 1. What are the controls in place that under normal conditions should function well to prevent embezzlements or frauds?...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT