import java.io.*; /** * LoanApplication is the main class for creating a loan and calculating payments. */ public class LoanApplication { private Loan m_loan; private String m_summary; /** * The run method provides a simple command-line interface loop. * It continually prompts for information for creating a new loan * and displays the summary of each loan entered. */ public void run() { PrintSpooler spooler = PrintSpooler.getSpooler(); try { for (;;) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please enter the applicant's name (enter nothing to quit):"); String name = br.readLine(); if (name.equals("")) break; System.out.print("Enter the interest rate: "); double rate = Double.parseDouble(br.readLine()); System.out.print("Enter the number of years: "); int years = Integer.parseInt(br.readLine()); System.out.print("Enter the principal balance: "); double principal = Double.parseDouble(br.readLine()); int type = 0; while (type < 1 || type > 2) { System.out.println("Please select whether the loan is a simple interest loan or an amortized loan:"); System.out.println("Select:"); System.out.println(" 1) simple interest loan"); System.out.println(" 2) amortized loan"); type = Integer.parseInt(br.readLine()); } Loan loan = (type == 1) ? new SimpleLoan(name, rate, years, principal) : new AmortizedLoan(name, rate, years, principal); System.out.println(""); spooler.printDocument(loan.process()); } } catch (Exception e) { } } }