/************************************************* to column 80...
 Program:          Millionare Winnings Calculator

 Author:           Mark Rich
 Date:             2/28/00

 Course:           CS 302, Fall '99, Section 29 + 8

 Compiler:         Java from Sun
 Platform:         Windows NT 4.0
*********************************************** to column 80... */
import javabook.*;

/**
 * This class will calculate the winnings for a contestant on
 * the popular gameshow "Who wants to be a Millionare?".  It is
 * an example of when the use of a switch statement without breaks
 * could be warranted to make the coding easier, such that once
 * a matching case is found, the winnings will cascade down to the 
 * break and accumulate the money.
 **/
class Millionare {

    /**
     * Our main class here instantiates the javabook objects, talks
     * to the user to get the number of questions answered, then 
     * calculates the winning using a "no break" switch statement.
     **/
    public static void main(String[] args) {
	
	// Creation of javabook necessary objects
	MainWindow mainWindow = new MainWindow();
	InputBox in = new InputBox(mainWindow);
	OutputBox out = new OutputBox(mainWindow);
	mainWindow.show();
	out.show();

	// Ask the user for the number of questions answered
	int questions = in.getInteger("How many questions did you " +
				      "answer correctly?");
	
	// Initialize their winnings to $0.
	int winnings = 0;

	// Switch on the number of questions answered correctly
	// to find the total winnings
	switch (questions) {
	    case 15: 
		winnings += 500000;
		out.printLine("You're a Millionare! Congratulations!");
	    case 14: 
		winnings += 250000;
	    case 13: 
		winnings += 125000;
	    case 12: 
		winnings += 61000;
	    case 11: 
		winnings += 32000;
	    case 10: 
		winnings += 16000;
		out.printLine("You reached the second lock-in point!");
	    case 9: 
		winnings += 8000;
	    case 8: 
		winnings += 4000;
	    case 7: 
		winnings += 2000;
	    case 6: 
		winnings += 1000;
	    case 5: 
		winnings += 500;
		out.printLine("You reached the first lock-in point!");
	    case 4: 
		winnings += 200;
	    case 3: 
		winnings += 100;
	    case 2: 
		winnings += 100;
	    case 1: 
		winnings += 100;
		break;
	    default: 
		out.printLine("Liar!  The number you entered is invalid.");
	}

	// Display the total winnings to the screen
	out.printLine("Your total winnings for tonight are $"+
			   winnings + ".");
    }
}
