import java.io.*;
import java.util.Scanner;

/** Input and Output main program
 *
 * @author Duncan Buell
 *
 * written: 18 October 2007
*/
public class Main extends Object
{

  public static void main(String[] args)
  {
    boolean goodData;
    String inputString = null;
    Scanner console = new Scanner(System.in);
    Loan myLoan = new Loan();

    System.out.printf("Input loan principal in dollars: ");
    inputString = console.next();
    goodData = myLoan.setPrincipal(inputString);
    if(false == goodData)
    {
      System.out.println("ERROR: input value " + inputString + " is not valid for the principal");
      System.exit(0);
    }
    else
    {
      System.out.println("Loan principal is: " + myLoan.getPrincipal());
    }

//
// For illustration purposes, I will do the input as part of the main program.
// In a real program, I would probably turn this into a method 'getData' or
// with a similar name and put the method inside the 'Loan' class.
//
    System.out.printf("Input loan rate (input '5' for '5.0%%': ");
    inputString = console.next();
    goodData = myLoan.setRate(inputString);
    if(false == goodData)
    {
      System.out.println("ERROR: input value " + inputString + " is not valid for the rate");
      System.exit(0);
    }
    else
    {
      System.out.println("Loan rate is: " + myLoan.getRate());
    }

    System.out.printf("Input loan payoff in dollars: ");
    inputString = console.next();
    goodData = myLoan.setPayoff(inputString);
    if(false == goodData)
    {
      System.out.println("ERROR: input value " + inputString + " is not valid for the payoff");
      System.exit(0);
    }
    else
    {
      System.out.println("Loan payoff is: " + myLoan.getPayoff());
    }

    myLoan.amortize();

    System.out.println("Loan information processed, terminate");

  }
} // public class Main extends Object

