// Program LoanCalculator (Step 2)


import javabook.*;

/**
 * Introduction to OOP with Java 2nd Edition, McGraw-Hill
 *   
 *  Chapter 4
 *
 * <p>
 * This class handles the input, computation, and output of loan
 * calculation.
 *
 * @author Dr. Caffeine 
 */
class LoanCalculator
{
//----------------------------------
//    Data Members
//----------------------------------

    /**
     * Constant for the number of months in a year
     */
    private final int MONTHS_IN_YEAR = 12;
      
    /**
     * The main window of the program
     */
    private MainWindow mainWindow;
         
    /**
     * InputBox for getting three input values
     */
    private InputBox  inputBox;
    
    /**
     * OutputBox for displaying the input values
     * and the payments
     */
    private OutputBox outputBox;

    /**
     * Input to the program - the amount of the loan
     */
    private float    loanAmount;
    
    /**
     * Input to the program - the annual interest rate
     */
    private float  annualInterestRate;
    
    /**
     * The monthly interest rate
     */
    private float  monthlyInterestRate;
    
    /**
     * The monthly loan payment
     */
    private double  monthlyPayment;
    
    /**
     * The total loan payment
     */
    private double totalPayment;

    /**
     * Input to the program - the loan period in years
     */
    private int   loanPeriod;
    
    /**
     * The number of monthly payments
     */
    private int  numberOfPayments;


//----------------------------------
//    Constructors
//----------------------------------

    public LoanCalculator()
    {
        mainWindow  = new MainWindow("L O A N  C A L C U L A T O R");
        inputBox    = new InputBox(mainWindow);
        outputBox   = new OutputBox(mainWindow);
    }

//-------------------------------------------------
//      Public Methods:
// 
//          void start (        )
//
//------------------------------------------------
                                
    /**
     * Top level method that calls other private methods
     * to compute the monthly and total loan payments
     */
    public void start()
    {
        mainWindow.setVisible( true );
        outputBox.setVisible( true );
        
        describeProgram();   //tell waht the program does
        getInput();          //get three input values
        computePayment();    //compute the monthly payment and total
        displayOutput();     //diaply the results
   }

//-------------------------------------------------
//      Private Methods:
// 
//      void    computePayment    (        )
//      void    describeProgram   (        )
//      void    displayOutput     (        )
//      void    getInputs         (        )
//
//------------------------------------------------
                                
    /**
     * Computes the monthly and total loan payments.
     */
    private void computePayment()
    {
        outputBox.printLine("inside computePayment");   //TEMP
    }

    /**
     * Provides a brief explaination of the program to the user.
     */
    private void describeProgram()
    {
        outputBox.printLine("inside describeProgram");   //TEMP
    }


    /**
     * Display the input values and monthly and total payments.
     */
    private void displayOutput() 
    {
        outputBox.printLine("inside displayOutput");   //TEMP
    }   


    /**
     * Gets three input values--loan amount, interest rate, and
     * loan period--using an InputBox object
     */
    private void getInput() 
    {
        loanAmount          = inputBox.getFloat("Loan Amount (Dollars&Cents):");
        annualInterestRate  = inputBox.getFloat("Annual Interest Rate (e.g. 9.5):");
        loanPeriod          = inputBox.getInteger("Loan Period - # of years:");

        //TEMP
        outputBox.printLine("Loan Amount: $" + loanAmount);
        outputBox.printLine("Annual Interest Rate: " + annualInterestRate + "%");
        outputBox.printLine("Loan Period (years): " + loanPeriod);
        //TEMP    
    }
    
}