Search This Blog

Sunday 17 August 2014

10. HTML and JSP Program Handle the Functionalities of a Shop.

Filename: Shop.html
<!-- 10. HTML program to design an interface for a shop. -->
<html>
 <head>

  <title>Shop Details</title>
 </head>
 <body>
 <h3>Program to handle the functionalities of a shop.</h3>
 <h4>Fill all the following fields.<h4>
 <form name="form1" action="Shop.jsp" method="POST">
   
    <b>Item Number&nbsp;:<input type="text" name="text1"><br><br>
    Item Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<input type="text" name="text2"><br><br>
    Item Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<select name="select1" >
                    <option value="Books">Books</option>
                    <option value="Handbags">Handbags</option>
                    <option value="Software">Software</option>

                 </select> <br><br>
    Unit Price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<input type="text" name="text3"><br><br>
    Quantity&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<input type="text" name="text4"><br><br>
    <input type="Submit" value="Calculate" style="height:30px; width:80px">
    <input type="Reset" value="Reset" style="height:30px; width:80px">
    </b>
 </form>

 </body>
</html>


Filename:  Shop.jsp
<!-- 10. JSP program handle the functionalities of a shop. -->
<html>
<body>

<h3>Program to handle the functionalities of a shop.</h3>
<h3>Details of Transaction:</h3>
<%
    String Item_Number=request.getParameter("text1");
    String Item_Name=request.getParameter("text2");
    String Item_Type=request.getParameter("select1");
    float Unit_Price=Float.parseFloat(request.getParameter("text3"));
    int qty=Integer.parseInt(request.getParameter("text4"));
    double Discount;
    double Price;
    double Amount;
    Price= Unit_Price * qty;
    //out.println("*"+Item_type+"*");

%>
<%
    if(Item_Type.compareTo("Books")==0)
    {
        out.println("10% Discount on Books");
        Discount=Price * 0.1;
    }
    else if(Item_Type.compareTo("Handbags")==0)
    {
        out.println("20% Discount on Handbag");
        Discount=Price * 0.2;
    }
    else if(Item_Type.compareTo("Software")==0)
    {
        out.println("15% Discount on Softwares");
        Discount=Price * 0.15;
    }
    else
    {
        out.println("Select any value");
        Discount=0;
    }
    Amount = Price - Discount;
%>

      
    <table border=3 cellpadding=10 cellspacing=5 bordercolor="blue">
    <b>
    <tr><td>Item Number</td><td><%=Item_Number%></td></tr>
    <tr><td>Item Name</td><td><%=Item_Name%></td></tr>
    <tr><td>Item Type</td><td><%=Item_Type%></td></tr>
    <tr><td>Unit Price</td><td><%=Unit_Price%></td></tr>
    <tr><td>Quantity</td><td><%=qty%></td></tr>
    <tr><td>Price</td><td><%=Price%></td></tr>
    <tr><td>Discount</td><td><%=Discount%></td></tr>
    <tr><td>Amount</td><td><%=Amount%></td></tr>
    </b>
    </table>

</body>
</html>

No comments :

Post a Comment

FREE Hit Counters