package Games; 
import java.util.*; 
public class KBC 
{ 
String questions[]; 
String options[][]; 
int answers[]; 
long money[]; 
int history[]; 
boolean lifelines[]; 
static int games=0; 
public int getRandomQuestion() 
{ 
int i=(int)((Math.random()*questions.length)); 
return i; 
} 
public KBC() //constructor 
{ 
questions=new String[] 
{ 
"Who discovered Uranus? ", 
"According to Hindu Mythology, which of these is a 
brother of God Krishna ?", 
" In the U.S., something traditional is often said to be 
"as American as" what?", 
"The velocity of light was first measured by", 
"Study of life in outer space is known as", 
"Oncology is the study of ", 
"What was the name of India's first unmanned lunar 
spacecraft launched in October 2008?", 
"The credit of developing the polio vaccine goes to", 
"The scientist who first discovered that the earth 
revolves round the sun was", 
"Centigrade & Fahrenheit scales give same reading at", 
"The unit of energy in MKS system is", 
"Which of the following instruments is used to measure 
pressure of gases?", 
"Where is the headquarters of Microsoft located?", 
"'.BAT' extension refers usually to what kind of file?", 
"What is the highest score in international test 
cricket?", 
"What was the overall medal tally for the Indian 
contingent at the Glasgow Commonwealth Games 2014?", 
"Which of these laws helps specifically in calculating 
current in complex circuits with multiple cells?", 
"The photoelectric effect was explained effectively by 
Einstein on the basis of what?" 
}; 
options=new String[][] 
{
{"1. Herschel ", "2. Galileo", "3. Copernicus ", "4. 
None of these "}, 
{"1. Ram ", "2. Balram ", "3. Arjun ", "4. Parsuram"}, 
{"1. Apple Pie ", "2. Franks and Beans ", "3. American 
Pie ", "4. Macaroni and cheese "}, 
{"1. Einstein", "2. Newton ", "3. Romer ", "4. Galileo 
"}, 
{"1. Endobiology ", "2. Exobiology", "3. Enterobiology 
", "4. Neobiology "}, 
{"1. Birds", "2. Cancer", "3. Mammals", "4. Soil"}, 
{"1. Chandravahaan 1" , "2. Chandrayaan 1 ", "3. 
Chandravimaan 1", "4. Chadrakhoj 1"}, 
{"1. Jonas Salk ", "2. Alb E. Sabin ", "3. Selman 
Waksman ", "4. None of these "}, 
{"1. Newton", "2. Dalton", "3. Copernicus", "4. 
Einstein"}, 
{"1. -40 degree", "2. -32 degree", "3. -273 degree", "4. 
-100 degree"}, 
{"1. Volt", "2. Erg", "3. Ohm", "4. Joule"}, 
{"1. Barometer ", "2. Manometer ", "3. Saccharimeter ", 
"4. Lactometer "}, 
{"1. Santa Clara, California ", "2. Tucson, Arizona ", 
"3. Richmond, Virginia ", "4. Redmond, Washington"}, 
{"1. Compressed Archive file ", "2. System file ", "3. 
Audio file ", "4. Backup file "}, 
{"1. 333","2. 427","3. 400*","4. 512"}, 
{"1. 62","2. 58","3. 64","4. 65" }, 
{"1. Kirchoff's law","2. Coulomb's law","3. Ohm's 
law","4. Gauss' theorem"}, 
{"1. Special relativity","2. Planck's quantum 
theory","3. Rutherford's postulates","4. Crystal field theory"} 
}; 
answers=new int[]{1,2,1,3,2,2,2,1,3,1,4,2,4,2,3,3,1,2}; 
money=new long[] 
{1000,3000,5000,10000,25000,50000,75000,100000,250000,500000,1000000 
,2500000,5000000,7500000,10000000}; 
history=new int[18]; 
lifelines=new boolean[]{false,false,false}; 
} 
public static void main() 
{ 
Scanner sc= new Scanner(System.in); 
int choice= 0; 
if(games==10) 
System.out.println("get a life"); 
if(games==0) 
System.out.println("fWelcome to KBCnn"); 
System.out.println("Your First Question is :n"); 
KBC k= new KBC(); //object 
int n=0;//no of questions completed 
for(int i=0;i<k.questions.length;i++) 
{
int r; 
do 
{ 
r= k.getRandomQuestion(); 
}while(k.history[r]==1); //loop goes till question is 
found which has not been asked yet 
System.out.println(k.questions[r]); 
System.out.println(k.options[r][0]); 
System.out.println(k.options[r][1]); 
System.out.println(k.options[r][2]); 
System.out.println(k.options[r][3]); 
System.out.println("Press 1,2,3 or 4nIf you do not know 
the answer enter 0 to use a lifeline"); 
choice= sc.nextInt(); 
while(choice>4) 
{ 
System.out.println("Please enter only 0,1,2,3 or 
4"); 
choice=sc.nextInt(); 
} 
if(choice==0) 
{ 
boolean boo=true; 
if(k.lifelines[0]==true && k.lifelines[1]==true && 
k.lifelines[2]==true) 
boo=false; 
if(boo){ 
System.out.println("Enter 1 to use 50/50nEnter 2 to 
ask RajnikanthnEnter 3 to change the question"); 
int c=sc.nextInt()-1; 
while(k.lifelines[c]==true) 
{ 
System.out.println("Sorry you have used this 
lifeline. Please choose another by entering the respective 
number."); 
c=sc.nextInt()-1; 
} 
k.lifelines[c]=true; 
switch(c) 
{ 
case 0: 
int rand; 
do{ 
rand=(int)(Math.random()*4); 
}while(rand==(k.answers[i]-1)); 
if(rand<(k.answers[r]-1)) 
System.out.println("The remaining options 
aren"+k.options[r][rand]+"n"+k.options[r][(k.answers[r]-1)]); 
else 
System.out.println("The remaining options 
aren"+k.options[r][(k.answers[r]-1)]+"n"+k.options[r][rand]); 
break;
case 1: 
System.out.println("Rajnikanth says the 
answer is "+k.answers[r]); 
break; 
case 2: 
k.history[r]=1; 
System.out.println("fYour new question is: 
n"); 
continue; 
} 
} 
else 
System.out.println("Sorry you have used all your 
lifelines."); 
System.out.println("What is your final answer?"); 
choice=sc.nextInt(); 
} 
n++; 
if(choice==k.answers[r]) 
{ 
if(n==15) 
System.out.println("nCorrect answer 
nCONGRATULATIONS!!!YOU ARE A CROREPATI!nYou Won Rs."+k.money[i] 
+"nnThanks for playing :)"); 
else 
System.out.println("nCorrect answernYou Won 
Rs."+k.money[i]+"n"); 
} 
else 
{ 
System.out.println("nYou LostnnGame Over !!"); 
if(i>=1) 
System.out.println("Your total prize 
money :Rs."+k.money[i-1]); 
else 
System.out.println("Your total prize money :Rs.0"); 
break; 
} 
k.history[r]=1; //indicates question is completed 
System.out.println("Enter any letter to continue"); 
String v=sc.next(); 
System.out.println("f");//refresh feed 
} 
System.out.println("Do you want to play again?(y/n)"); 
char c=sc.next().charAt(0); 
if(c=='y' || c=='Y') 
{ 
games++; 
main(); 
} 
else 
System.out.println("Thanks for playing!"); 
} 
}
KBC (Java Program written on Blue J Editor)

KBC (Java Program written on Blue J Editor)

  • 1.
    package Games; importjava.util.*; public class KBC { String questions[]; String options[][]; int answers[]; long money[]; int history[]; boolean lifelines[]; static int games=0; public int getRandomQuestion() { int i=(int)((Math.random()*questions.length)); return i; } public KBC() //constructor { questions=new String[] { "Who discovered Uranus? ", "According to Hindu Mythology, which of these is a brother of God Krishna ?", " In the U.S., something traditional is often said to be "as American as" what?", "The velocity of light was first measured by", "Study of life in outer space is known as", "Oncology is the study of ", "What was the name of India's first unmanned lunar spacecraft launched in October 2008?", "The credit of developing the polio vaccine goes to", "The scientist who first discovered that the earth revolves round the sun was", "Centigrade & Fahrenheit scales give same reading at", "The unit of energy in MKS system is", "Which of the following instruments is used to measure pressure of gases?", "Where is the headquarters of Microsoft located?", "'.BAT' extension refers usually to what kind of file?", "What is the highest score in international test cricket?", "What was the overall medal tally for the Indian contingent at the Glasgow Commonwealth Games 2014?", "Which of these laws helps specifically in calculating current in complex circuits with multiple cells?", "The photoelectric effect was explained effectively by Einstein on the basis of what?" }; options=new String[][] {
  • 2.
    {"1. Herschel ","2. Galileo", "3. Copernicus ", "4. None of these "}, {"1. Ram ", "2. Balram ", "3. Arjun ", "4. Parsuram"}, {"1. Apple Pie ", "2. Franks and Beans ", "3. American Pie ", "4. Macaroni and cheese "}, {"1. Einstein", "2. Newton ", "3. Romer ", "4. Galileo "}, {"1. Endobiology ", "2. Exobiology", "3. Enterobiology ", "4. Neobiology "}, {"1. Birds", "2. Cancer", "3. Mammals", "4. Soil"}, {"1. Chandravahaan 1" , "2. Chandrayaan 1 ", "3. Chandravimaan 1", "4. Chadrakhoj 1"}, {"1. Jonas Salk ", "2. Alb E. Sabin ", "3. Selman Waksman ", "4. None of these "}, {"1. Newton", "2. Dalton", "3. Copernicus", "4. Einstein"}, {"1. -40 degree", "2. -32 degree", "3. -273 degree", "4. -100 degree"}, {"1. Volt", "2. Erg", "3. Ohm", "4. Joule"}, {"1. Barometer ", "2. Manometer ", "3. Saccharimeter ", "4. Lactometer "}, {"1. Santa Clara, California ", "2. Tucson, Arizona ", "3. Richmond, Virginia ", "4. Redmond, Washington"}, {"1. Compressed Archive file ", "2. System file ", "3. Audio file ", "4. Backup file "}, {"1. 333","2. 427","3. 400*","4. 512"}, {"1. 62","2. 58","3. 64","4. 65" }, {"1. Kirchoff's law","2. Coulomb's law","3. Ohm's law","4. Gauss' theorem"}, {"1. Special relativity","2. Planck's quantum theory","3. Rutherford's postulates","4. Crystal field theory"} }; answers=new int[]{1,2,1,3,2,2,2,1,3,1,4,2,4,2,3,3,1,2}; money=new long[] {1000,3000,5000,10000,25000,50000,75000,100000,250000,500000,1000000 ,2500000,5000000,7500000,10000000}; history=new int[18]; lifelines=new boolean[]{false,false,false}; } public static void main() { Scanner sc= new Scanner(System.in); int choice= 0; if(games==10) System.out.println("get a life"); if(games==0) System.out.println("fWelcome to KBCnn"); System.out.println("Your First Question is :n"); KBC k= new KBC(); //object int n=0;//no of questions completed for(int i=0;i<k.questions.length;i++) {
  • 3.
    int r; do { r= k.getRandomQuestion(); }while(k.history[r]==1); //loop goes till question is found which has not been asked yet System.out.println(k.questions[r]); System.out.println(k.options[r][0]); System.out.println(k.options[r][1]); System.out.println(k.options[r][2]); System.out.println(k.options[r][3]); System.out.println("Press 1,2,3 or 4nIf you do not know the answer enter 0 to use a lifeline"); choice= sc.nextInt(); while(choice>4) { System.out.println("Please enter only 0,1,2,3 or 4"); choice=sc.nextInt(); } if(choice==0) { boolean boo=true; if(k.lifelines[0]==true && k.lifelines[1]==true && k.lifelines[2]==true) boo=false; if(boo){ System.out.println("Enter 1 to use 50/50nEnter 2 to ask RajnikanthnEnter 3 to change the question"); int c=sc.nextInt()-1; while(k.lifelines[c]==true) { System.out.println("Sorry you have used this lifeline. Please choose another by entering the respective number."); c=sc.nextInt()-1; } k.lifelines[c]=true; switch(c) { case 0: int rand; do{ rand=(int)(Math.random()*4); }while(rand==(k.answers[i]-1)); if(rand<(k.answers[r]-1)) System.out.println("The remaining options aren"+k.options[r][rand]+"n"+k.options[r][(k.answers[r]-1)]); else System.out.println("The remaining options aren"+k.options[r][(k.answers[r]-1)]+"n"+k.options[r][rand]); break;
  • 4.
    case 1: System.out.println("Rajnikanthsays the answer is "+k.answers[r]); break; case 2: k.history[r]=1; System.out.println("fYour new question is: n"); continue; } } else System.out.println("Sorry you have used all your lifelines."); System.out.println("What is your final answer?"); choice=sc.nextInt(); } n++; if(choice==k.answers[r]) { if(n==15) System.out.println("nCorrect answer nCONGRATULATIONS!!!YOU ARE A CROREPATI!nYou Won Rs."+k.money[i] +"nnThanks for playing :)"); else System.out.println("nCorrect answernYou Won Rs."+k.money[i]+"n"); } else { System.out.println("nYou LostnnGame Over !!"); if(i>=1) System.out.println("Your total prize money :Rs."+k.money[i-1]); else System.out.println("Your total prize money :Rs.0"); break; } k.history[r]=1; //indicates question is completed System.out.println("Enter any letter to continue"); String v=sc.next(); System.out.println("f");//refresh feed } System.out.println("Do you want to play again?(y/n)"); char c=sc.next().charAt(0); if(c=='y' || c=='Y') { games++; main(); } else System.out.println("Thanks for playing!"); } }