Win 98 Error:
------------------
[04/04/2000 19:48:31:850 EDT] java.lang.InstantiationException: Mortgage
_
at java.lang.Class.newInstance0(Native Method)
_
at java.lang.Class.newInstance(Class.java, Compiled Code)
_
at
org.apache.jserv.JServServletManager.load_init(JServServletManager._
at
org.apache.jserv.JServServletManager.loadServlet(JServServletManage_
at
org.apache.jserv.JServConnection.processRequest(JServConnection.jav_
at org.apache.jserv.JServConnection.run(JServConnection.java:188)
_
at java.lang.Thread.run(Thread.java:479)
_
Linux Error
---------------
[Tue Apr 4 18:33:58 2000] [notice] suEXEC mechanism enabled (wrapper:
/usr/sbi)
java.lang.NoSuchMethodError
at org.apache.jserv.JServServletManager.load_init(Compiled Code)
at org.apache.jserv.JServServletManager.loadServlet(Compiled Code)
at org.apache.jserv.JServConnection.processRequest(Compiled Code)
at org.apache.jserv.JServConnection.run(Compiled Code)
at java.lang.Thread.run(Compiled Code)
Java Code
---------------
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Mortgage extends HttpServlet {
double prin;
double rate;
double payment;
int term;
Mortgage(double p,double r,int t) {
this.prin = p;
this.rate = r;
this.term = t;
this.payment=round2d(calcpayment());
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
double pp = Double.valueOf(req.getParameter("prin")).doubleValue();
double rr = Double.valueOf(req.getParameter("rate")).doubleValue();
int tt = Integer.parseInt(req.getParameter("term"));
Mortgage m = new Mortgage(pp,rr,tt);
m.amortize();
}
double calcpayment(){
double tmp;
double monthly_interest = ((rate / 12.0) / 100.0);
tmp = 1.0 - java.lang.Math.pow((monthly_interest + 1.0),
(double)(-term));
return(monthly_interest * prin / tmp);
}
void amortize(){
double applied_prin;
double interest_paid;
int i;
System.out.println("<HTML>");
System.out.println("<HEAD><TITLE>Loan Amortization by Java
Servlets</TITLE></HEAD>");
System.out.println("<BODY>");
System.out.println("\nMonth # Balance Prin Paid Int Paid
Total Payment\n\n");
for(i=1; i <= term; i++) {
interest_paid = round2d(((rate / 12.0) / 100.0) * prin);
applied_prin = round2d(payment - interest_paid);
printform(i,prin, applied_prin, interest_paid, payment);
prin = round2d(prin - applied_prin);
}
System.out.println("</BODY></HTML>");
}
void printform(int i,double prin, double applied_prin, double
interest_paid, double payment) {
String s = new String();
DecimalFormat df = new
DecimalFormat("0,000,000,000.00;0,000,000,000.00CR");
DecimalFormat nf = new DecimalFormat("0000");
System.out.println( ltrim(nf.format(i))
+ ltrim(df.format(prin))
+ ltrim(df.format(applied_prin))
+ ltrim(df.format(interest_paid))
+ ltrim(df.format(payment))
);
}
String ltrim(String formatStr) {
StringBuffer s = new StringBuffer(formatStr);
for(int i=0;i<s.length();i++)
if(s.charAt(i) == '0' || s.charAt(i) == ',')
s.setCharAt(i, ' ');
else
break;
return(String.valueOf(s));
}
double round2d(double round_in){
return (java.lang.Math.floor(round_in * 100. + .5) / 100);
}
}
regards,
Krishna.