Skip to main content

Who Wants To Be A Millionaire Java Game Page

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; who wants to be a millionaire java game

private void useAskAudience(Question q) System.out.println("\n*** ASK THE AUDIENCE ***"); int correct = q.correctOption; int[] votes = new int[4]; int remaining = 100; votes[correct] = 40 + random.nextInt(30); // majority for correct remaining -= votes[correct]; for (int i = 0; i < 4; i++) if (i != correct) votes[i] = random.nextInt(remaining / 2); remaining -= votes[i]; // Give leftovers to first wrong for (int i = 0; i < 4; i++) if (i != correct && votes[i] == 0) votes[i] = remaining; break; System.out.println("Audience votes:"); for (int i = 0; i < 4; i++) System.out.printf(" %c: %d%%\n", (char) ('A' + i), votes[i]); audienceUsed = true; private int getGuaranteedPrize() if (currentLevel &gt

public Question(String text, String[] options, int correctOption, int level) this.text = text; this.options = options; this.correctOption = correctOption; this.level = level; SAFE_LEVEL_2) return PRIZES[SAFE_LEVEL_2 - 1]

private Question[] questions; private int currentLevel; // 1-based private boolean fiftyUsed, phoneUsed, audienceUsed; private Scanner scanner; private Random random;

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 loadQuestions() questions = new Question[15]; // Level 1 questions[0] = new Question("What is the capital of France?", new String[]"Berlin", "Madrid", "Paris", "Lisbon", 2, 1); // Level 2 questions[1] = new Question("Which planet is known as the Red Planet?", new String[]"Mars", "Jupiter", "Venus", "Saturn", 0, 2); // Level 3 questions[2] = new Question("Who painted the Mona Lisa?", new String[]"Van Gogh", "Picasso", "Da Vinci", "Rembrandt", 2, 3); // Level 4 questions[3] = new Question("What is the largest ocean on Earth?", new String[]"Atlantic", "Indian", "Arctic", "Pacific", 3, 4); // Level 5 questions[4] = new Question("Which year did World War II end?", new String[]"1943", "1944", "1945", "1946", 2, 5); // Level 6 questions[5] = new Question("Who wrote 'Romeo and Juliet'?", new String[]"Charles Dickens", "Jane Austen", "Mark Twain", "William Shakespeare", 3, 6); // Level 7 questions[6] = new Question("What is the square root of 144?", new String[]"10", "11", "12", "13", 2, 7); // Level 8 questions[7] = new Question("Which element has the chemical symbol 'O'?", new String[]"Gold", "Oxygen", "Osmium", "Silver", 1, 8); // Level 9 questions[8] = new Question("Who directed the movie 'Jurassic Park'?", new String[]"James Cameron", "Steven Spielberg", "George Lucas", "Ridley Scott", 1, 9); // Level 10 questions[9] = new Question("Which country gifted the Statue of Liberty to the USA?", new String[]"England", "Spain", "France", "Germany", 2, 10); // Level 11 questions[10] = new Question("What is the hardest natural substance?", new String[]"Iron", "Gold", "Diamond", "Platinum", 2, 11); // Level 12 questions[11] = new Question("Who discovered penicillin?", new String[]"Marie Curie", "Alexander Fleming", "Louis Pasteur", "Isaac Newton", 1, 12); // Level 13 questions[12] = new Question("Which city hosted the 2016 Summer Olympics?", new String[]"London", "Rio de Janeiro", "Tokyo", "Beijing", 1, 13); // Level 14 questions[13] = new Question("What is the longest river in the world?", new String[]"Amazon", "Nile", "Yangtze", "Mississippi", 1, 14); // Level 15 questions[14] = new Question("Who painted the Sistine Chapel ceiling?", new String[]"Leonardo da Vinci", "Raphael", "Donatello", "Michelangelo", 3, 15);