52 lines
1.7 KiB
Java
52 lines
1.7 KiB
Java
|
|
import java.io.*;
|
|
|
|
public class LoanApplication
|
|
{
|
|
private Loan m_loan;
|
|
private String m_summary;
|
|
|
|
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);
|
|
|
|
spooler.printDocument(loan.process());
|
|
}
|
|
}
|
|
catch (Exception e) { }
|
|
}
|
|
}
|