gvsu/cs621/proj3/LoanApplication.java
josh 8818779daf commented, calculating interests
git-svn-id: svn://anubis/gvsu@74 45c1a28c-8058-47b2-ae61-ca45b979098e
2008-03-21 20:48:42 +00:00

61 lines
2.0 KiB
Java

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) { }
}
}