PROGRAM TO CREATE ELECTRIC BILL USING JSP

ebbillform.html


<html>
<body>

<form  action="ebbillcalc.jsp" method="post">

<h2><div style="text-align:center">TAMILNADU ELECTRICITY BOARD</div></h2>

<table BORDER="1" >
<CAPTION><EM> ELECTRICITY BILL</EM></CAPTION>

<tr rowspan="2">
<th> Consumer Name:</th>
<td><input type="text" name="conname"></td>
</tr>

<tr>
<th> Connection no:</th>
<td><input type="text" name="conno"></td>
</tr>

<tr>
<th> Date:</th>
<td><input type="text" name="condate"></td>
</tr>

<tr>
<th> Zone Name:</th>
<td><input type="text" name="conzn"></td>
</tr>

<tr>
<th>Previous meter reading :</th>
<td><input type="text" name="conpmr"></td>
</tr>

<tr>
<th> Current meter reading:</th>
<td><input type="text" name="concmr"></td>
</tr>


</table>

</br></br></br>

   <input type="submit" value="Submit" />
</form>

</body>
</html>

ebbillcalc.jsp


<%@ page import="java.io.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.lang.util.*"%>
<%@ page import="javax.servlet.ServletException"%>
<%@ page import="javax.servlet.http.HttpServletRequest"%>

<html>
<body>

<%
try{
String cname=request.getParameter("conname");
String cno=request.getParameter("conno");
String cndate=request.getParameter("condate");
String cnzn=request.getParameter("conzn");
String cnpmr=request.getParameter("conpmr");
String cncmr=request.getParameter("concmr");


int cnpmr1=Integer.parseInt(cnpmr);
int cncmr1=Integer.parseInt(cncmr);

int units=cncmr1-cnpmr1;
int runits=units-100;
double tamt=0.0;

if (runits > 100){
        if (runits >= 200){
             tamt=tamt+(100.0*2.00);
        }else{
              tamt=tamt+(runits*2.00);

}}
         
if (runits > 201){
          if (runits > 400){
              tamt=tamt+(200.0*4.00);
          }else{
             runits=runits-100;
             tamt=tamt+(runits*4.00);
             }   
}
             
if (runits > 400){
        if(runits > 600){
            tamt=tamt+(runits*6.00);
        } else{
           runits=runits-400;
           tamt=tamt+(runits*6.00);
          }
}
%>
<form target="_blank">
<h2><div style="text-align:center">TAMILNADU ELECTRICITY BOARD</div></h2>

<table BORDER="1" >
<CAPTION><EM> ELECTRICITY BILL</EM></CAPTION>

<tr rowspan="2">
<th> Consumer Name:</th>
<td><input type="text" name="conname" value=<%=cname%>></td>
</tr>

<tr>
<th> Connection no:</th>
<td><input type="text" name="conno" value=<%=cno%>></td>
</tr>

<tr>
<th> Date:</th>
<td><input type="text" name="condate" value=<%=cndate%>></td>
</tr>

<tr>
<th> Zone Name:</th>
<td><input type="text" name="conzn" value=<%=cnzn%>></td>
</tr>

<tr>
<th>Previous meter reading :</th>
<td><input type="text" name="conpmr"value=<%=cnpmr%>></td>
</tr>

<tr>
<th> Current meter reading:</th>
<td><input type="text" name="concmr" value=<%=cncmr%>></td>
</tr>

<tr>
<th> Units consumed:</th>
<td><input type="text" name="conunits" value=<%=units%>></td>
</tr>

<tr>
<th> Amount to be paid:</th>
<td><input type="text" name="conamt" value=<%=tamt%>></td>
</tr>

</table>
         
</form>
<%

}
catch(NumberFormatException exp){
      out.println("There is something wrong:"+exp);
}
%>

</body>
</html>

OUTPUT:



No comments:

Post a Comment