Who Wants To Be A Millionaire Java Game -
while (currentLevel <= 15) displayPrizeLadder(); Question currentQ = questions[currentLevel - 1]; boolean correct = askQuestion(currentQ);
Enter choice (A/B/C/D), 'W' to walk away, 'L' for lifelines: C
while (true) System.out.print("\nEnter choice (A/B/C/D), 'W' to walk away, 'L' for lifelines: "); String input = scanner.nextLine().trim().toUpperCase(); if (input.equals("W")) System.out.println("You walked away with $" + getGuaranteedPrize()); System.exit(0); else if (input.equals("L")) if (!fiftyUsed else int answerIndex = -1; switch (input) case "A": answerIndex = 0; break; case "B": answerIndex = 1; break; case "C": answerIndex = 2; break; case "D": answerIndex = 3; break; default: System.out.println("Invalid input."); continue; if (answerIndex == q.correctOption) System.out.println("\n✅ Correct! You've won $" + PRIZES[currentLevel - 1]); return true; else System.out.println("\n❌ Wrong! The correct answer was " + (char)('A' + q.correctOption) + ": " + q.options[q.correctOption]); return false; who wants to be a millionaire java game
public static void main(String[] args) MillionaireGame game = new MillionaireGame(); game.start();
public MillionaireGame() scanner = new Scanner(System.in); random = new Random(); currentLevel = 1; fiftyUsed = false; phoneUsed = false; audienceUsed = false; loadQuestions(); while (currentLevel <
private void useFiftyFifty(Question q) System.out.println("\n*** 50:50 LIFELINE USED ***"); int correct = q.correctOption; java.util.ArrayList<Integer> wrong = new java.util.ArrayList<>(); for (int i = 0; i < 4; i++) if (i != correct) wrong.add(i); // Remove two random wrong answers java.util.Collections.shuffle(wrong); java.util.HashSet<Integer> keep = new java.util.HashSet<>(); keep.add(correct); keep.add(wrong.get(0)); // keep one wrong answer for (int i = 0; i < 4; i++) if (keep.contains(i)) System.out.println((char) ('A' + i) + ": " + q.options[i]); else System.out.println((char) ('A' + i) + ": [removed]"); fiftyUsed = true;
private void displayPrizeLadder() System.out.println("\n===== PRIZE LADDER ====="); for (int i = 0; i < PRIZES.length; i++) if (i + 1 == currentLevel) System.out.printf("-> Level %2d: $%,d (current)\n", i + 1, PRIZES[i]); else System.out.printf(" Level %2d: $%,d\n", i + 1, PRIZES[i]); System.out.println("========================\n"); = 15) displayPrizeLadder()
public Question(String text, String[] options, int correctOption, int level) this.text = text; this.options = options; this.correctOption = correctOption; this.level = level;