Logo 
Search:

OOAD Articles

Submit Article
Home » Articles » OOAD » Servlet RSS Feeds

From an insurance company a person takes a policy of 1 lakh rupees. If he takes this insurance for 25 years he has to pay a premium of Rs.4000/year

Posted By: Milind Mishra     Category: OOAD     Views: 2034

From an insurance company a person takes a policy of 1 lakh rupees. If he takes this insurance for 25 years he has to pay a premium of Rs.4000/year if for 30 years the a premium of Rs.3000/year. If the person is a lady and a housewife the 5% deduction will be given but if a workingwoman the no deduction will be given. Write a servlet, which takes input from an HTML client page and calculates and outputs the premium amount.

Code for From an insurance company a person takes a policy of 1 lakh rupees. If he takes this insurance for 25 years he has to pay a premium of Rs.4000/year in OOAD

// premium.html

<html>
<body>
<form action="http://localhost:1977/examples/servlet/PremiumServlet" method="POST">
Enter Name of the person : <input type="text" name="person_name">

<br>
<br>

Select no. of years:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<select name="num_years">
<option value="25years" selected>25 years </option>
<option value="30years"> 30 years </option>
</select>
<br>
<br>
Select criteria :&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<select name="criteria">
<option value="working_male">Working Male </option>
<option value="working_lady">Working lady </option>
<option value="lady_housewife">Lady housewife </option>
</select>
<br>
<br>
<input type="submit" name="Go"value="Find Premium Amount">

</form>
</body> </html>


// PremiumServlet.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

publicclass PremiumServlet extends HttpServlet
{

  publicvoid doPost(HttpServletRequest req, HttpServletResponse res)
  throws ServletException, IOException
  {

    try
    {
      
        String name_of_person="";     
        String years="";
        String criteria="";     
    double prem_val=0;       
    name_of_person = req.getParameter("person_name");       
    years = req.getParameter("num_years");
        criteria=req.getParameter("criteria");

        if(criteria.equals("working_male")||criteria.equals("working_lady"))
    {
           if(years.equals("25years"))
           { 
             PrintWriter out = res.getWriter();
             out.println("Premium to be paid by "+name_of_person+" is Rs 4000/year");
             out.close(); //Close the output stream
               }
           
        elseif(years.equals("30years"))
            { 
          PrintWriter out = res.getWriter();
              out.println("Premium to be paid by "+name_of_person+" is Rs 3000/year");
              out.close(); //Close the output stream
            }
    }
    if(criteria.equals("lady_housewife"))
    {
           if(years.equals("25years"))
           { 
             PrintWriter out = res.getWriter();
                 prem_val=4000-((5*4000)/100);
         out.println("Premium to be paid by "+name_of_person+" is Rs "+prem_val+"/year");
             out.close(); //Close the output stream
               }
           
        elseif(years.equals("30years"))
            { 
         PrintWriter out = res.getWriter();
                 prem_val=3000-((5*3000)/100);
             out.println("Premium to be paid by "+name_of_person+" is Rs "+prem_val+"/year");
             out.close(); //Close the output stream
            }
    }



    }
  catch (Exception e)
    {  System.out.println("Error " + e);
    }
  }
}


// OUTPUT

(1)

------------------------
ON HTML FORM INPUTS ARE:
------------------------
Enter Name of the person :  dharini modi

Select no. of years: 25 years 

Select criteria : Working lady  
---------
RESPONSE
---------
Premium to be paid by  dharini modi is Rs 4000/year


(2)

------------------------
ON HTML FORM INPUTS ARE:
------------------------
Enter Name of the person :   dharini modi

Select no. of years: 30 years 

Select criteria : Lady housewife  
---------
RESPONSE
---------
Premium to be paid by  dharini modi is Rs 2850.0/year

(2)

------------------------
ON HTML FORM INPUTS ARE:
------------------------
Enter Name of the person :  dharini modi

Select no. of years: 25 years 

Select criteria : Lady housewife  
---------
RESPONSE
---------
Premium to be paid by  dharini modi is Rs 3800.0/year


(4)

------------------------
ON HTML FORM INPUTS ARE:
------------------------
Enter Name of the person :  ashvin modi

Select no. of years: 30 years 

Select criteria : Working male  
---------
RESPONSE
---------
Premium to be paid by ashvin modi is Rs 3000/year

  
Share: 



Milind Mishra
Milind Mishra author of From an insurance company a person takes a policy of 1 lakh rupees. If he takes this insurance for 25 years he has to pay a premium of Rs.4000/year is from India.
 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in OOAD:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!