if (correct) if (currentLevel == 15) System.out.println("\nπππ CONGRATULATIONS! YOU ARE A MILLIONAIRE! πππ"); System.out.println("You win $1,000,000!"); break; currentLevel++; else int prize = getGuaranteedPrize(); System.out.println("\nGame over! You leave with $" + prize); break; scanner.close();
public void start() System.out.println("====================================="); System.out.println(" WHO WANTS TO BE A MILLIONAIRE?"); System.out.println("====================================="); System.out.println("Rules: Answer 15 questions. Use lifelines wisely."); System.out.println("Walk away anytime by typing 'W'.\n"); who wants to be a millionaire java game
public MillionaireGame() scanner = new Scanner(System.in); random = new Random(); currentLevel = 1; fiftyUsed = false; phoneUsed = false; audienceUsed = false; loadQuestions(); if (correct) if (currentLevel == 15) System
Enter choice (A/B/C/D), 'W' to walk away, 'L' for lifelines: C You leave with $" + prize); break; scanner
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")) !phoneUsed 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;
public static void main(String[] args) MillionaireGame game = new MillionaireGame(); game.start();
private int getGuaranteedPrize() if (currentLevel > SAFE_LEVEL_2) return PRIZES[SAFE_LEVEL_2 - 1]; else if (currentLevel > SAFE_LEVEL_1) return PRIZES[SAFE_LEVEL_1 - 1]; else return 0;