Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class WWTBAM {
- public static void main (String[]args) {
- Scanner sc= new Scanner (System.in);
- int lifeline1=1;//to check if the user has used the lifeline
- int lifeline2;// to determine which answer is chosen by the computer
- int fiftyfifty=1;//to check if fifty fifty has been used
- int ff1,ff2;// to determine whichanswer will appear before another
- int audience=1;//to check if ask the audience has been used
- int wage=0;//to calculate the ending wage
- int streak=1;//this will be turned to 0 and the game will be over if the useer enters the wrong answer
- int rand=1;//to randomize questions
- int audRand=0;
- int count=0;
- String input,quest,ans,name,input2;
- int [] aud=new int[4];
- int [] quests=new int[16];//for each question
- int [] rands=new int [16];//for the program to not repeat questions
- int [] wages=new int [14];
- String [] words=new String[4];//for each inidividual answer
- /*
- * Variable Initialization
- */
- for (int i =0; i<quests.length;i+=1){
- quests[i] =1;
- }
- for (int i =0; i<rands.length;i+=1){
- rands[i] =0;
- }
- ans="";
- quest="";
- ff1=-1;
- ff2=-1;
- wages[0]=0;
- wages[1]=100;
- wages[2]=200;
- wages[3]=500;
- wages[4]=1000;
- wages[5]=2000;
- wages[6]=5000;
- wages[7]=10000;
- wages[8]=20000;
- wages[9]=50000;
- wages[10]=100000;
- wages[11]=200000;
- wages[12]=500000;
- wages[13]=1000000;
- /*
- * End of initialization
- */
- System.out.println ("Welcome to Who wants to be a Millionaire!");
- System.out.println ("The objective of the game is to answer trivia questions to earn up to $1000000");
- System.out.println("If you get the question wrong, you will lose and your wage will be your last check point if you earned any");
- System.out.println ("Today's subject will be Lord of the Rings");
- System.out.println ("Please enter your name");
- name=sc.nextLine();//Name for the final wage at the end
- while (wage<13) {
- if (wage<5) {
- rand = (int)(Math.random() * 6) +1;//Easy difficulty questions
- } else if (wage>=5 && wage <9){
- rand = (int)(Math.random() * 6) +7;//Medium difficulty questions
- }else if (wage>=9 &&wage <12){
- rand = (int)(Math.random() *4) +12;//Hard difficulty questions
- }else if (wage==12){
- rand=16;//Final question
- }
- /*
- * For each question I initialized the same 6 variables over and over
- */
- if (rand==1){
- ans= "A";
- quest= "What is the name of the wizard accompanying the Fellowship of the Ring?";
- words[0]="A. Gandalf";//The array is to help
- words[1]="B. Dumbledore";
- words[2]="C. Harry Potter";
- words[3]="D. Aragorn";
- }else if(rand==2){
- ans= "B";
- quest= "What is the name of the main villain in the main trilogy?";
- words[0]="A. Zeus";
- words[1]="B. Sauron";
- words[2]="C. Palpatine";
- words[3]="D. Cthulhu";
- }else if (rand==3){
- ans= "A";
- quest= "What is the name of Frodo’s village in the Fellowship of the Ring?";
- words[0]="A. The Shire";
- words[1]="B. The Village";
- words[2]="C. Mordor";
- words[3]="D. Rivendell";
- }else if (rand ==4){
- ans= "C";
- quest= "What are the names of the nine commanders that Sauron leads?";
- words[0]="A. Ghosts";
- words[1]="B. Death Eaters";
- words[2]="C. Nazgul";
- words[3]="D. Fellbeasts";
- }else if (rand==5){
- ans= "B";
- quest= "What is the name of the kingdom that Denethor rules during the Return of the King?";
- words[0]="A. Minas Tirith";
- words[1]="B. Gondor";
- words[2]="C. Boromir";
- words[3]="D. Faramir";
- }else if (rand==6){
- ans= "D";
- quest= "Who was the wizard that served under Sauron during the War of the Ring?";
- words[0]="A. Gandalf";
- words[1]="B. Frodo";
- words[2]="C. Elrond";
- words[3]="D. Saruman";
- }else if (rand==7){
- ans= "C";
- quest= "What is the name of Gandalf's sword?";
- words[0]="A. Sting";
- words[1]="B. Gurthang";
- words[2]="C. Glamdring";
- words[3]="D. Anglachel";
- }else if (rand==8){
- ans= "D";
- quest= "Finish the quote: 'One Ring to rule them all, One Ring to find them, One Ring to bring them all and";
- words[0]="A. Mordor shall blind them";
- words[1]="B. No man shall grind them";
- words[2]="C. Sauron shall bind them";
- words[3]="D. In the darkness bind them";
- }else if (rand==9){
- ans= "A";
- quest= "Who directed the Lord of the Rings Trilogy?";
- words[0]="A. Peter Jackson";
- words[1]="B. Steven Spielberg";
- words[2]="C. James Gunn";
- words[3]="D. Viggo Mortensen";
- }else if (rand==10){
- ans= "C";
- quest= "What was Gollum's original name before being corrupted by the power of the ring?";
- words[0]="A. Deagol";
- words[1]="B. Meriadoc";
- words[2]="C. Smeagol";
- words[3]="D. Beren";
- }else if (rand==11){
- ans= "B";
- quest= "What is the name of the book about the Lord of the Rings Franchise that was published after J.R.R. Tolkien(the author) died?";
- words[0]="A. The Hobbit";
- words[1]="B. Silmarilion";
- words[2]="C. Beren and Luthien";
- words[3]="D. The Adventures of Tom Bombadil";
- }else if (rand==12){
- ans= "B";
- quest= "What is the name of the immortal wizards that include Gandalf and Saruman?";
- words[0]="A. Valar";
- words[1]="B. Istar";
- words[2]="C. Ainur";
- words[3]="D. Maiar";
- }else if (rand==13){
- ans= "C";
- quest= "Who is the creator and god of Middle-Earth??";
- words[0]="A. Melkor";
- words[1]="B. Varda";
- words[2]="C. Eru Illuvitar";
- words[3]="D. Gandalf";
- }else if (rand==14){
- ans= "B";
- quest= "What is the name of Beren's Lover who sacrifices herself to be with him?";
- words[0]="A. Lorien";
- words[1]="B. Luthien";
- words[2]="C. Galadriel";
- words[3]="D. Feanor";
- }else if (rand==15){
- ans= "A";
- quest= "What three swords were found in the Troll's cave in 'The Hobbit'?";
- words[0]="A. Orcist,Sting, and Glamdring";
- words[1]="B. Narsil,Glamdring, and Hadhafang";
- words[2]="C. Sting,Anduil, and the White Knife of Legolas";
- words[3]="D. Aeglos,Orcrist, and Sting";
- }else if (rand==16){
- ans= "D";
- quest= "In the prophesized final battle (Dagor Dagorath), who is the man who will finally finish off Morgoth forever?";
- words[0]="A. Tulkas";
- words[1]="B. Earendil";
- words[2]="C. Eonwe";
- words[3]="D. Turin Turambar";
- }
- rands[rand-1]+=1;//if the question has been asked once,it will not be asked again
- if (rands[rand-1]==1) {//if the question has not been asked
- count+=1;
- System.out.print(count +". ");
- System.out.println (quest);//outputting the question and answers
- System.out.println (words[0]);
- System.out.println (words[1]);
- System.out.println (words[2]);
- System.out.println (words[3]);
- if (lifeline1==1) {
- System.out.println ("1. Lifeline ");
- } if(fiftyfifty==1) {
- System.out.println ("2. Fifty Fifty ");
- } if(audience==1) {
- System.out.println ("3. Ask the audience ");
- }
- while (true){
- input=sc.nextLine();
- if (input.equalsIgnoreCase("a")||input.equalsIgnoreCase("b")||input.equalsIgnoreCase("c")||input.equalsIgnoreCase("d")) {//if user inputs a,b,c, or d
- if (input.equalsIgnoreCase(ans)){//if the answer is correct
- wage +=1;
- System.out.println ("Correct!");
- }else {//the 3 wrong options
- streak =0;
- System.out.println ("Incorrect");
- }
- break;//the user validation will end
- } else if (input.equals("1")) {//this lifeline has an 80% chance of being correct, and chooses a random wrong answer if is not correct
- if (lifeline1==1){//
- lifeline2 = (int)(Math.random() * 5) +1;
- System.out.println ("Guest:");
- if (lifeline2 >=2) {
- System.out.println ("I think the answer is "+ans);
- }else {
- if (ans.equals("A")){
- lifeline2 = (int)(Math.random() * 3) +1;
- if (lifeline2==1){
- System.out.println ("I think the answer is B");
- }else if (lifeline2==2){
- System.out.println ("I think the answer is C");
- }else if (lifeline2==3){
- System.out.println ("I think the answer is D");
- }
- } else if (ans.equals("B")){
- lifeline2 = (int)(Math.random() * 3) +1;
- if (lifeline2==1){
- System.out.println ("I think the answer is A");
- }else if (lifeline2==2){
- System.out.println ("I think the answer is C");
- }else if (lifeline2==3){
- System.out.println ("I think the answer is D");
- }
- } else if (ans.equals("C")){
- lifeline2 = (int)(Math.random() * 3) +1;
- if (lifeline2==1){
- System.out.println ("I think the answer is A");
- }else if (lifeline2==2){
- System.out.println ("I think the answer is B");
- }else if (lifeline2==3){
- System.out.println ("I think the answer is D");
- }
- } else if (ans.equals("D")){
- lifeline2 = (int)(Math.random() * 3) +1;
- if (lifeline2==1){
- System.out.println ("I think the answer is A");
- }else if (lifeline2==2){
- System.out.println ("I think the answer is B");
- }else if (lifeline2==3){
- System.out.println ("I think the answer is C");
- }
- }
- }
- lifeline1=0;
- }else{
- System.out.println ("You have already used this lifeline");
- }
- }else if (input.equals("2")) {//This lifeline outputs 2 final options, the correct one and one incorrect answer
- if (fiftyfifty==1) {
- if (ans.equalsIgnoreCase("A")){
- ff2=0;
- ff1 = (int)(Math.random() * 3) +1;
- } else if (ans.equalsIgnoreCase("B")){
- ff2=1;
- ff1 = (int)(Math.random() * 4);
- if (ff1==ff2){
- while (ff1==ff2){
- ff1 = (int)(Math.random() * 4);
- }
- }
- } else if (ans.equalsIgnoreCase("C")){
- ff2=2;
- ff1 = (int)(Math.random() * 4);
- if (ff1==ff2){
- while (ff1==ff2){
- ff1 = (int)(Math.random() * 4);
- }
- }
- } else if (ans.equalsIgnoreCase("D")){
- ff2=3;
- ff1 = (int)(Math.random() * 3);
- }
- if (ff2>ff1){
- System.out.println(quest);
- System.out.println(words[ff1]);
- System.out.println(words[ff2]);
- } else if (ff1>ff2){
- System.out.println(quest);
- System.out.println(words[ff2]);
- System.out.println(words[ff1]);
- }
- fiftyfifty=0;
- }else {
- System.out.println("You have already used this lifeline");
- }
- }else if (input.equals("3")){//this lifeline is completely random and has no positive effect on the user's choices
- if (audience==1){
- while (aud[0]+aud[1]+aud[2]+aud[3]<100){
- audRand = (int)(Math.random() * 4);
- aud[audRand]+=1;
- }
- for (int i=0;i<=3;i+=1){
- System.out.print(aud[i] +"% of the audience voted for ");
- if (i==0){
- System.out.println ("A");
- }else if (i==1){
- System.out.println ("B");
- }else if (i==2){
- System.out.println ("C");
- }else if (i==3){
- System.out.println ("D");
- }
- audience=0;
- }
- } else {
- System.out.println("You have already used this lifeline");
- }
- }else{ //if the user inputs anything other than a,b,c,d,1,2,or 3
- System.out.println ("Invalid");
- }
- }
- if (streak==0){//is the user gets the wrong answer
- break;
- }
- }
- if (wage==5||wage==9){
- System.out.println("Congratulations, you reached a checkpoint!");
- }
- System.out.println("Your current wage is $" +wages[wage]);
- if (wage<13){
- System.out.println("Would you like to walk away?(yes or no)");
- while (true) {
- input2=sc.nextLine();
- if (input2.equalsIgnoreCase("yes")){
- break;
- }else if (input2.equalsIgnoreCase("no")){
- break;
- }else{
- System.out.println("Invalid");
- }
- }
- if (input2.equals("yes")){
- break;
- }
- }
- }
- if (streak==0){
- if (wage<5){
- wage=0;
- }else if (wage>=5&&wage<9){
- wage=5;
- }else if (wage>=9){
- wage=9;
- }
- }
- System.out.println ("Congratulations, " + name + ", you earned $" +wages[wage]);
- }
Advertisement
Add Comment
Please, Sign In to add comment