Develop a Loan Calculator Program in Servlet

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.text.*;
public class RegPayS extends HttpServlet {
double principal;
double intRate;
double numYears;
final int payPerYear = 12;
NumberFormat nf;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String payStr = "";
nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
String amountStr = request.getParameter("amount");
String periodStr = request.getParameter("period");
String rateStr = request.getParameter("rate");
try {
if(amountStr != null && periodStr != null &&
rateStr != null) {
principal = Double.parseDouble(amountStr);
numYears = Double.parseDouble(periodStr);
intRate = Double.parseDouble(rateStr) / 100;
payStr = nf.format(compute());
}
else {
amountStr = "";
periodStr = "";
rateStr = "";
}
} catch (NumberFormatException exc) {
// Take appropriate action here.
}

response.setContentType("text/html");

PrintWriter pw = response.getWriter();

pw.print("" +
"

" + "Enter amount to finance:" + " "); pw.print(" Enter term in years:" + " "); pw.print(" Enter interest rate:" + " "); pw.print(" Monthly Payment:" + " "); pw.print(" "); pw.println("
"); } double compute() { double numer; double denom; double b, e; numer = intRate * principal / payPerYear; e = -(payPerYear * numYears); b = (intRate / payPerYear) + 1.0; denom = 1.0 - Math.pow(b, e); return numer / denom; } }