can anyone please modify the lifelines part of this Java code? 1. when the user
ID: 3651653 • Letter: C
Question
can anyone please modify the lifelines part of this Java code?1. when the user enters "ff", (50:50 lifeline), 2 of the 4 choices in the question currently being answered are removed, leaving the user with only 2 choices to choose from.. however currently in this code, it automatically removes choices c and d even if the answer is in either a or b.. so I need a modification that will not remove the correct choice but rather remove 2 of the wrong choices
2. the lifelines can only be used by the player only once per round (easy, average, hard) then the player must be told that he has already used the lifeline for the current level.. however currently in this code, the lifelines can be used thrice for the WHOLE game and not once per round..
so I need the modifications please.. thanks so much! by the way I am from the Philippines that is why the currency of the game is in Philippine pesos
import java.io.*;
import java.util.*;
class Millionaire
{
private String choice;
private static int counter = 0;
private static int lifeline = 3;
public static int moneyCounterEASY()
{
counter = counter + 10000;
return (counter);
}
public static int moneyCounterAVE()
{
counter = counter + 50000;
return (counter);
}
public static int moneyCounterHARD()
{
counter = counter + 100000;
return (counter);
}
public static void Mechanics()
{
System.out.println(" Mechanics:");
System.out.println("|==========================================================================|");
System.out.println(" The player will be given a set of questions.");
System.out.println(" For each correct answer, ");
System.out.println(" the player's money will automatically increase");
System.out.println(" until he reaches the maximum ");
System.out.println(" amount of 1 Million Pesos.");
System.out.println(" During the game, if the player gets a wrong answer, ");
System.out.println(" he will go home with nothing. ");
System.out.println("|===========================================================================|");
System.out.println(" For every correct answer in the easy round, +P10,000. ");
System.out.println(" For every correct answer in the medium round, +P50,000. ");
System.out.println(" For every correct answer in the hard round, +P100,000. ");
System.out.println("|==========================================================================|");
System.out.println(" LIFELINES: Press 'ff' to use lifeline");
System.out.println("|=========================================================================|");
System.out.println(" You will be given one lifeline PER ROUND: 50:50. ");
System.out.println(" This means 2 of the 4 choices will be removed. ");
System.out.println(" You will have 3 chances to use this lifeline throughout the whole game. ");
System.out.println(" Use it wisely! |");
System.out.println("|==========================================================================|");
}
public static void EasyRound()
{
try
{
System.out.println(" EASY ROUND FIRST!");
BufferedReader fileIn = new BufferedReader(new FileReader("Easy.txt"));
BufferedReader KeyIn = new BufferedReader(new InputStreamReader(System.in));
LinkedList<String> Easy = new LinkedList<String>();
for (int i = 0; i < 25; i++)
{
// EASY Question
Easy.add(fileIn.readLine());
}
for (int i = 0; i < 10; i++)
{
System.out.println(" For Php " + (moneyCounterEASY())+ ", here is the question: ");
System.out.println(" Question #" + (i + 1) + ":");
int R = (int) (25 * Math.random());
String Q = Easy.remove(R);
String[] token = Q.split("::");
String question;
question = token[1];
System.out.println(question);
System.out.println(" a) " + token[2] + " b) " + token[3]+ " c) " + token[4] + " d) " + token[5]);
// input user's answer
System.out.print(" Answer: ");
String userAns = KeyIn.readLine();
if (userAns.equals("ff"))
{
if(lifeline == 0)
{
System.out.println("Sorry, You have used up all 3 lifeline chances.");
}
else
{
int removed = 0;
for(int j=0;j<4;j++)
{
if(removed < 2 && !token[j+2].equals(token[6]))
{
removed++;
}
else
{
System.out.print(" "+(char)(97+j)+") "+token[j+2]);
}
}
System.out.println();
lifeline--;
}
System.out.print(" Answer: ");
userAns = KeyIn.readLine();
}
if (userAns.equals(token[6]))
{
System.out.println("Your answer's CORRECT!");
}
else if (!userAns.equals(token[6]))
{
System.out.println("SORRY, you won't get any prize. Thank you for trying!");
System.exit(0);
}
}
}// Exception stuff
catch (IndexOutOfBoundsException hehe)
{
System.out.println("There's something wrong.");
System.out.println(hehe.toString());
}
catch (FileNotFoundException haha)
{
System.out.println("There's something wrong.");
System.out.println(haha.toString());
}
catch (IOException hihi)
{
System.out.println("There's something wrong.");
System.out.println(hihi.toString());
}
finally
{
System.out.println("There's something wrong.");
}
}
public static void AverageRound()
{
try
{
System.out.println(" CONGRATULATIONS!");
System.out.println(" You reached the AVERAGE ROUND.");
System.out.println("You now have Php 100,000!");
BufferedReader fileIn = new BufferedReader(new FileReader("Average.txt"));
BufferedReader KeyIn = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Would you still like to continue [yes/no]? ");
String cont = KeyIn.readLine();
if(cont.equals("no"))
{
System.out.println("You won Php 100,000! Thank you for playing!");
System.exit(0);
}
else if(cont.equals("yes"))
{
System.out.println("Now let's start the 2nd round! GOOD LUCK!");
}
LinkedList<String> Average = new LinkedList<String>();
for (int i = 0; i < 17; i++)
{
// Average Question
Average.add(fileIn.readLine());
}
for (int i = 0; i < 10; i++)
{
System.out.println(" For Php " + (100000+moneyCounterAVE())+ ", here is the question: ");
System.out.println(" Question #" + (i + 1) + ":");
int R = (int) (17 * Math.random());
String Q = Average.remove(R);
String[] token = Q.split("::");
String question;
question = token[1];
System.out.println(question);
System.out.println(" a) " + token[2] + " b) " + token[3]+ " c) " + token[4] + " d) " + token[5]);
// input user's answer
System.out.print(" Answer: ");
String userAns = KeyIn.readLine();
if (userAns.equals("ff"))
{
if(lifeline == 0)
{
System.out.println("Sorry, You have used up all 3 lifeline chances.");
}
else
{
int removed = 0;
for(int j=0;j<4;j++)
{
if(removed < 2 && !token[j+2].equals(token[6]))
{
removed++;
}
else
{
System.out.print(" "+(char)(97+j)+") "+token[j+2]);
}
}
System.out.println();
lifeline--;
}
System.out.print(" Answer: ");
userAns = KeyIn.readLine();
}
if (userAns.equals(token[6]))
{
System.out.println("Your answer's CORRECT! Next question.");
}
else if (!userAns.equals(token[6]))
{
System.out.println("SORRY, you won't get any prize. THANK YOU FOR TRYING!");
System.exit(0);
}
}
}
catch (IndexOutOfBoundsException hehe)
{
System.out.println("There's something wrong.");
System.out.println(hehe.toString());
}
catch (FileNotFoundException haha)
{
System.out.println("There's something wrong.");
System.out.println(haha.toString());
}
catch (IOException hihi)
{
System.out.println("There's something wrong.");
System.out.println(hihi.toString());
}
finally
{
System.out.println("There's something wrong.");
}
}
public static void HardRound()
{
try
{
System.out.println(" CONGRATULATIONS!");
System.out.println(" You reached the HARD ROUND.");
System.out.println("You now have Php 600,000!");
BufferedReader fileIn = new BufferedReader(new FileReader("Hard.txt"));
BufferedReader KeyIn = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Would you still like to continue [yes/no]? ");
String cont = KeyIn.readLine();
if(cont.equals("no"))
{
System.out.println("You won Php 600,000! Thank you for playing!");
System.exit(0);
}
else if(cont.equals("yes"))
{
System.out.println("Now let's start the 3rd round! GOOD LUCK!");
}
LinkedList<String> Hard = new LinkedList<String>();
for (int i = 0; i < 28; i++)
{
// HARD Questions
Hard.add(fileIn.readLine());
}
for (int i = 0; i < 4; i++)
{
System.out.println(" For Php " + (600000+moneyCounterHARD())+ ", here is the question: ");
System.out.println(" Question #" + (i + 1) + ":");
int R = (int) (28 * Math.random());
String Q = Hard.remove(R);
String[] token = Q.split("::");
String question;
question = token[1];
System.out.println(question);
System.out.println(" a) " + token[2] + " b) " + token[3]+ " c) " + token[4] + " d) " + token[5]);
// input user's answer
System.out.print(" Answer: ");
String userAns = KeyIn.readLine();
if (userAns.equals("ff"))
{
if(lifeline == 0)
{
System.out.println("Sorry, You have used up all 3 lifeline chances.");
}
else
{
int removed = 0;
for(int j=0;j<4;j++)
{
if(removed < 2 && !token[j+2].equals(token[6]))
{
removed++;
}
else
{
System.out.print(" "+(char)(97+j)+") "+token[j+2]);
}
}
System.out.println();
lifeline--;
}
System.out.print(" Answer: ");
userAns = KeyIn.readLine();
}
if (userAns.equals(token[6]))
{
System.out.println("Your answer's CORRECT!");
}
else if (!userAns.equals(token[6]))
{
System.out.println("SORRY, you won't get any prize. THANK YOU FOR TRYING!");
System.exit(0);
}
}
}
catch (IndexOutOfBoundsException hehe)
{
System.out.println("There's something wrong.");
System.out.println(hehe.toString());
}
catch (FileNotFoundException haha)
{
System.out.println("There's something wrong.");
System.out.println(haha.toString());
}
catch (IOException hihi)
{
System.out.println("There's something wrong.");
System.out.println(hihi.toString());
}
finally
{
System.out.println("There's something wrong.");
}
}
}
/*====================================MAIN==================================*/
public class WWTBAM
{
public static void main(String[] args) throws Exception
{
try
{
BufferedReader KeyIn = new BufferedReader(new InputStreamReader(System.in));
Millionaire A = new Millionaire();
System.out.print(" Hello! What's your name? ");
String nickName = KeyIn.readLine();
System.out.println(" Welcome to 'Who wants to be a Millionaire?' Game, "+nickName+"!");
System.out.println("Would you like to know the mechanics?");
System.out.println("[n] for no [y] for yes.");
System.out.print("User: ");
String ansMech = KeyIn.readLine();
if (ansMech.equals("y")) {
A.Mechanics();
}
if (!ansMech.equals("n")) {
System.out.println(" NOW LET'S START!");
}
// Start the game~
System.out.println("|==========================================================================|");
// This is where the questions will be given, etc.
A.EasyRound();
A.AverageRound();
A.HardRound();
System.out.println("You have answered all the questions CORRECTLY!!");
System.out.println("CONGRATULATIONS, " + nickName + "!!");
System.out.println("YOU HAVE WON PHP 1,000,000!!");
System.out.println(" |==========================================================================|");
}
catch (IndexOutOfBoundsException hehe)
{
System.out.println("There's something wrong.");
System.out.println(hehe.toString());
}
catch (FileNotFoundException haha)
{
System.out.println("There's something wrong.");
System.out.println(haha.toString());
}
catch (IOException hihi)
{
System.out.println("There's something wrong.");
System.out.println(hihi.toString());
}
finally
{
System.out.println("There's something wrong.");
}
}
}
Explanation / Answer
public static int moneyCounterAVE() { counter = counter + 50000; return (counter); } public static int moneyCounterHARD() { counter = counter + 100000; return (counter); } public static void Mechanics() { System.out.println(" Mechanics:"); System.out.println("|==========================================================================|"); System.out.println(" The player will be given a set of questions."); System.out.println(" For each correct answer, "); System.out.println(" the player's money will automatically increase"); System.out.println(" until he reaches the maximum "); System.out.println(" amount of 1 Million Pesos."); System.out.println(" During the game, if the player gets a wrong answer, "); System.out.println(" he will go home with nothing. "); System.out.println("|===========================================================================|"); System.out.println(" For every correct answer in the easy round, +P10,000. "); System.out.println(" For every correct answer in the medium round, +P50,000. "); System.out.println(" For every correct answer in the hard round, // input user's answer System.out.print(" Answer: "); String userAns = KeyIn.readLine(); if (userAns.equals("ff")) { if(lifeline == 0) { System.out.println("Sorry, You have used up all 3 lifeline chances."); } else { int removed = 0; for(int j=0;jRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.