Q. Write a program to implement a Miniature Quiz Game that will
have options for their answers. Design a program that will :
i) accept your name ;
ii) permission to start or end the game ;
iii) display message whether the option is correct or not ;
iv) display correct answer if the option entered is wrong ;
iv) at the end display result.
Example :
1.Which is the capital of India?
a) Kolkata
b) New Delhi
c) Mumbai
Choose your answer from the given options:(a/b/c)
and enter your answer.
b
CORRECT
Answer:
import java.util.*;
public class MINIATURE_QUIZ
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name _____________");
String n=sc.nextLine();
System.out.println("Welcome "+n+" Press 'S' to start or Press 'E' to end the
program");
char ch=(sc.next()).charAt(0);
int correctans=0;int incorrectans=0;float per=0.0f;
switch(ch)
{
case 'S':
String Q[]={"1.Which is the capital of India?","Who is
the President of India present currently?","3.What does Mohs scale
measure?","4.Which of these is used to sterilize drinking water and
purify swimming pools?","5.Scientifically, which of these is not a
tree?","6.Who wrote the famous poem 'If'?","7.Where is the
headquarter of UNESCO?","8.Which of these is the most widely used
non-ferrous metal?","9.Which of these is not inert
gas?","10.Which one of the following is commonly known as blue vitriol
and is used as a fungicide?","11.Which acid is present in
apple?","12.Decomposers are also known
as_____________.","13.Which one of the following options belong to
phytoplanktons?","14.The __________ is the basis of
MRI.","15.Who among the following gave the Left-Hand rule for the
direction of force?"};
String a[]={"a) Kolkata","a) Shri Ramnath
Koveind","a) Density","a) Iodine","a)
Teak","a) Lewis Carroll","a) Paris","a)
Nickel","a) Boron","a) Potassium nitrate","a)
Oxalic acid","a) Autotrophs","a) Algae","a)
Resistance","a) Fleming"};
String b[]={"b) New Delhi","b) Shri Pranab
Mukherjee","b) Velocity","b) Chlorine","b)
Banyan","b) Rudyard Kipling","b) New York","b)
Aluminium","b) Xenon","b) Copper sulphate","b)
Formic acid","b) Saprotrophs","b) Protozoa","b)
Pressure","b) Maxwell"};
String c[]={"c) Mumbai","c) Shri Venkaiah
Naidu","c) Hardness","c) Potassium","c)
Bamboo","c) Grimm Brothers","c) Geneva","c) Zinc","c)
Krypton","c) Sodium carbonate","c) Malic
acid","c) Tertiary consumers","c) Fungi","c)
Magnetism","c) Oersted"};
char
anskey[]={'b','a','c','b','c','b','a','b','a','b','c','b','a','c','a'};
char ans;int correct=0;
int incorrect=0;
System.out.println("GENERAL KNOWLEDGE QUESTIONS [Science, History
and Civics, Literature]");
System.out.println("Multiple Choice Questions(Each question comes
with three options.Choose the correct answers from the given options: a, b or
c):");
for(int i=0;i<15;i++)
{
System.out.println(Q[i]);
System.out.println(a[i]);
System.out.println(b[i]);
System.out.println(c[i]);
System.out.println("Choose
your answer from the given options:(a/b/c) and enter your answer.");
ans=(sc.next()).charAt(0);
if(ans==anskey[i])
{
correct++;
System.out.println("CORRECT");
}
else
{
incorrect++;
System.out.println("WRONG");
System.out.println("The correct answer is: "+anskey[i]);
ans=' ';
}
} // end of for loop
correctans=correctans+correct;
incorrectans=incorrectans+incorrect;
System.out.println("Number of correct answers:"+correctans);
System.out.println("Number of incorrect
answers:"+incorrectans);
System.out.println(n+" you have scored "+correctans+" out
of 15 questions");
per=(float)((correctans*100)/15);
System.out.println(n+" your percentage
is:"+per+"%");
if(per>=90)
System.out.println("Excellent Work");
else
if(per>=80 && per<90)
System.out.println("Very
Good");
else
if(per<80 && per>=70)
System.out.println("Good");
else
if(per<70 && per>=60)
System.out.println("Satisfactory");
else
if(per<60 && per>=50)
System.out.println("Fair");
else
if(per<50 && per>=40)
System.out.println("Needs
more updation");
else
System.out.println("Poor");
char f;
while(true)
{
System.out.println("Press
'F' or 'f' to finish the program");
f=(sc.next()).charAt(0);
if(f=='F' || f=='f')
System.exit(0);
} // end of while loop
case 'E':
System.exit(0);
default:
System.out.println("Wrong choice entered");
} // end of switch case
}
// end of method
} // end of class
OUTPUT
:
Enter your name _____________
Rohit Roy
Welcome Rohit Roy Press 'S' to start or Press 'E' to end the
program
S
GENERAL KNOWLEDGE QUESTIONS [Science,
History and Civics, Literature]
Multiple Choice Questions(Each question
comes with three options.Choose the correct answers from the given options: a,
b or c):
1.Which is the capital of India?
a) Kolkata
b) New Delhi
c) Mumbai
Choose your answer from the given
options:(a/b/c) and enter your answer.
b
CORRECT
Who is the President of India present
currently?
a) Shri Ramnath Koveind
b) Shri Pranab Mukherjee
c) Shri Venkaiah Naidu
Choose your answer from the given
options:(a/b/c) and enter your answer.
a
CORRECT
3.What does Mohs scale measure?
a) Density
b) Velocity
c) Hardness
Choose your answer from the given
options:(a/b/c) and enter your answer.
c
CORRECT
4.Which of these is used to sterilize
drinking water and purify swimming pools?
a) Iodine
b) Chlorine
c) Potassium
Choose your answer from the given
options:(a/b/c) and enter your answer.
b
CORRECT
5.Scientifically, which of these is not a
tree?
a) Teak
b) Banyan
c) Bamboo
Choose your answer from the given
options:(a/b/c) and enter your answer.
c
CORRECT
6.Who wrote the famous poem 'If'?
a) Lewis Carroll
b) Rudyard Kipling
c) Grimm Brothers
Choose your answer from the given
options:(a/b/c) and enter your answer.
b
CORRECT
7.Where is the headquarter of UNESCO?
a) Paris
b) New York
c) Geneva
Choose your answer from the given
options:(a/b/c) and enter your answer.
a
CORRECT
8.Which of these is the most widely used
non-ferrous metal?
a) Nickel
b) Aluminium
c) Zinc
Choose your answer from the given
options:(a/b/c) and enter your answer.
a
WRONG
The correct answer is: b
9.Which of these is not inert gas?
a) Boron
b) Xenon
c) Krypton
Choose your answer from the given
options:(a/b/c) and enter your answer.
a
CORRECT
10.Which one of the following is commonly
known as blue vitriol and is used as a fungicide?
a) Potassium nitrate
b) Copper sulphate
c) Sodium carbonate
Choose your answer from the given
options:(a/b/c) and enter your answer.
c
WRONG
The correct answer is: b
11.Which acid is present in apple?
a) Oxalic acid
b) Formic acid
c) Malic acid
Choose your answer from the given
options:(a/b/c) and enter your answer.
c
CORRECT
12.Decomposers are also known
as_____________.
a) Autotrophs
b) Saprotrophs
c) Tertiary consumers
Choose your answer from the given
options:(a/b/c) and enter your answer.
c
WRONG
The correct answer is: b
13.Which one of the following options
belong to phytoplanktons?
a) Algae
b) Protozoa
c) Fungi
Choose your answer from the given
options:(a/b/c) and enter your answer.
a
CORRECT
14.The __________ is the basis of MRI.
a) Resistance
b) Pressure
c) Magnetism
Choose your answer from the given
options:(a/b/c) and enter your answer.
a
WRONG
The correct answer is: c
15.Who among the following gave the
Left-Hand rule for the direction of force?
a) Fleming
b) Maxwell
c) Oersted
Choose your answer from the given
options:(a/b/c) and enter your answer.
b
WRONG
The correct answer is: a
Number of correct answers:10
Number of incorrect answers:5
Rohit Roy you have scored 10 out of 15
questions
Rohit Roy your percentage is:66.0%
Satisfactory
Press 'F' or 'f' to finish the program
f
VM
terminated.
Comments
Post a Comment