0% found this document useful (0 votes)
93 views5 pages

Ex2 - Creation of Interest Calculator Component in EJB

This document describes the creation of an interest calculator component using EJBs. It involves: 1) Creating an Index.jsp page to accept user input for loan details and submit to a servlet. 2) Developing an InterestCalcServlet class that calls methods on a remote EJB interface to calculate simple interest, compound interest, and EMI based on the input. 3) Implementing an InterestSessionBean EJB with methods to calculate simple interest, compound interest, and EMI based on a given loan amount, tenure, and interest rate.

Uploaded by

suganya004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views5 pages

Ex2 - Creation of Interest Calculator Component in EJB

This document describes the creation of an interest calculator component using EJBs. It involves: 1) Creating an Index.jsp page to accept user input for loan details and submit to a servlet. 2) Developing an InterestCalcServlet class that calls methods on a remote EJB interface to calculate simple interest, compound interest, and EMI based on the input. 3) Implementing an InterestSessionBean EJB with methods to calculate simple interest, compound interest, and EMI based on a given loan amount, tenure, and interest rate.

Uploaded by

suganya004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Creation of Interest Calculator Component in EJB.

Algorithm:

Index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>

<form name="Form"
action="http://localhost:8080/InterestCalculatorWebApp/InterestCalcServlet"
method="POST">
<table border="1" >
<thead>
<tr>
<th> <h1>Interest Calculator</h1></th>
</tr>
</thead>
<tbody>
<tr>
<td><table border="0">
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Loan Amount*</td>
<td><input type="text" name="txtamount" value=""
size="30" /></td>
</tr>
<tr>
<td>Loan Tenure (Year)*</td>
<td><input type="text" name="txtYear" value="" size="10"
/></td>
</tr>
<tr>
<td>Interest Rate (Reducing)*</td>
<td><input type="text" name="txtRate" value="" size="10"
/></td>
</tr>
<tr>
<td>Select Type of Interest*</td>
<td><select name="DDL">
<option value="Simple Interest">Simple Interest</option>
<option value="Compount Interest">Compount
Interest</option>
<option value="EMI">EMI</option>
</select></td>
</tr>
<tr>
<td></td>
<td> <input id="Submit1" type="submit" value="submit"
/></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>

</form>
</body>
</html>
InterestCalcServlet.java

import InterestCalculator.InterestSessionBeanRemote;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class InterestCalcServlet extends HttpServlet {


@EJB
private InterestSessionBeanRemote interestSessionBean;

protected void processRequest(HttpServletRequest request, HttpServletResponse


response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
int EMI = 0;
int SI=0;
int CI=0;
try {

/* EMI Calculation formula for Home Loan


L = Loan amount
i = Interest Rate (rate per annum divided by 12)
^ = to the power of
N = loan period in months */

int L=Integer.parseInt(request.getParameter("txtamount"));
double i=Double.parseDouble(request.getParameter("txtRate"));
int N=Integer.parseInt(request.getParameter("txtYear"));
String InterestStr=request.getParameter("DDL");
i=i/100;

out.println("<html>");
out.println("<head>");
out.println("<title>Servlet InterestCalcServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet InterestCalcServlet at " + request.getContextPath () +
"</h1>");
out.println(InterestStr);
if(InterestStr.equals("Simple Interest"))
{
SI=(int) interestSessionBean.SimpleInterest(L, N, i);
out.println("=Rs/-"+SI);
}
else if(InterestStr.equals("Compount Interest"))
{
CI=(int) interestSessionBean.CompoundInterest(L, N, i);
out.println("=Rs/-"+CI);
}
else if(InterestStr.equals("EMI"))
{
EMI=(int) interestSessionBean.EMI(L, N, i);
out.println("=Rs/-"+EMI);
}

out.println("</body>");
out.println("</html>");

} finally {
out.close();
}
}
EJB Component

package InterestCalculator;

import javax.ejb.Stateless;

@Stateless
public class InterestSessionBeanBean implements InterestSessionBeanRemote,
InterestSessionBeanLocal {

public double SimpleInterest(int Amount, int Nyear, double IRate) {


return (Amount*Nyear *IRate);
}

public double CompoundInterest(int Amount, int Nyear, double IRate) {


double temp=Math.pow((1 + IRate/12), Nyear);
return (Amount*temp);
}

public double EMI(int Amount, int Nyear, double IRate) {


double temp1=Amount*(IRate/12);
double temp2=(1+(IRate/12));
int months=Nyear*12;
double temp3=Math.pow(temp2, months);
return((temp1*temp3)/(temp3-1));
}

// Add business logic below. (Right-click in editor and choose


// "Insert Code > Add Business Method" or "Web Service > Add Operation")

You might also like