import java.util.Scanner;
public class InvestmentTest {
  public static void main(String[] arg) {
    Scanner in = new Scanner(System.in);
    
    char firstChar  = 'y';
    String answer = "";
    // loop while you keep getting answers starting with y
    do {
      
      System.out.print("Enter initial balance: ");
      double balance = in.nextDouble();
      System.out.print("Enter interest: ");
      double interest = in.nextDouble();
      System.out.print("Enter target balance: ");
      double target = in.nextDouble();
      Investment invest =
        new Investment(balance, interest);
      while ( balance <= 0 ||
             interest <= 0 ||
             target <= balance ) {
        System.out.println("That's invalid!");
        System.out.print("Enter initial balance: ");
        balance = in.nextDouble();
        System.out.print("Enter interest: ");
        interest = in.nextDouble();
        System.out.print("Enter target balance: ");
        target = in.nextDouble();
        invest = new Investment(balance, interest);
      }
      System.out.println("Years to go from " +
                         invest.getBalance() +
                         " to " + target +
                         " at interest " +
                         invest.getInterest() +
                         " is " +
                         invest.yearsForBalance(target));
      System.out.println("In 10 years, " + invest.getBalance()
                           + " at interest " + invest.getInterest()
                           + " will become " +
                         invest.balanceForYears(10));
      
      System.out.print("Would you like to continue? (y or n) ");
      answer = in.next();
      firstChar = answer.charAt(0);
    } while (firstChar == 'y');
  }
}