<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<
html
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
title
>Price Calculator</
title
>
<
style
>
#navbar {
background-color: #333;
overflow: hidden;
}
#navbar a {
float: left;
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
#navbar a:hover {
background-color: #ddd;
color: black;
}
</
style
>
</
head
>
<
body
>
<
div
id
=
"navbar"
>
<
a
href="<c:url
value
=
'products.jsp'
/>">All Products</
a
>
<
a
href="<c:url
value
=
'products.jsp'
>
<
c:param
name
=
"color"
value
=
"red"
/>
</
c:url
>">Red Products</
a
>
<
a
href="<c:url
value
=
'products.jsp'
>
<
c:param
name
=
"color"
value
=
"blue"
/>
</
c:url
>">Blue Products</
a
>
</
div
>
<
h2
>Item Order Form</
h2
>
<
form
action
=
"index.jsp"
method
=
"post"
>
Number of Red Shirts: <
input
type
=
"text"
name
=
"redShirts"
value
=
"0"
><
br
>
Number of Blue Pants: <
input
type
=
"text"
name
=
"bluePants"
value
=
"0"
><
br
>
Number of Red Hats: <
input
type
=
"text"
name
=
"redHats"
value
=
"0"
><
br
>
Number of Blue Jackets: <
input
type
=
"text"
name
=
"blueJackets"
value
=
"0"
><
br
>
Number of Green Socks: <
input
type
=
"text"
name
=
"greenSocks"
value
=
"0"
><
br
>
<
input
type
=
"submit"
value
=
"Calculate"
>
</
form
>
<
c:set
var
=
"redShirtPrice"
value
=
"4"
/>
<
c:set
var
=
"bluePantsPrice"
value
=
"7.5"
/>
<
c:set
var
=
"redHatPrice"
value
=
"2"
/>
<
c:set
var
=
"blueJacketPrice"
value
=
"9"
/>
<
c:set
var
=
"greenSocksPrice"
value
=
"1.2"
/>
<
c:if
test
=
"${not empty param.redShirts}"
>
<
c:set
var
=
"totalPrice"
value
=
"${param.redShirts * redShirtPrice + param.bluePants * bluePantsPrice + param.redHats * redHatPrice + param.blueJackets * blueJacketPrice + param.greenSocks * greenSocksPrice}"
/>
<
c:set
var
=
"totalItems"
value
=
"${param.redShirts + param.bluePants + param.redHats + param.blueJackets + param.greenSocks}"
/>
<
c:set
var
=
"discount"
value
=
"0"
/>
<
c:if
test="${totalItems > 10 && totalItems <= 25}">
<
c:set
var
=
"discount"
value
=
"${totalPrice * 0.07}"
/>
</
c:if
>
<
c:if
test="${totalItems > 25 && totalItems <= 50}">
<
c:set
var
=
"discount"
value
=
"${totalPrice * 0.10}"
/>
</
c:if
>
<
c:set
var
=
"finalPrice"
value
=
"${totalPrice - discount}"
/>
<
h3
>Order Summary:</
h3
>
<
table
border
=
"1"
>
<
tr
>
<
th
>Item</
th
>
<
th
>Quantity</
th
>
<
th
>Price per Item ($)</
th
>
<
th
>Subtotal ($)</
th
>
</
tr
>
<
tr
>
<
td
>Red Shirts</
td
>
<
td
>${param.redShirts}</
td
>
<
td
>${redShirtPrice}</
td
>
<
td
>${param.redShirts * redShirtPrice}</
td
>
</
tr
>
<
tr
>
<
td
>Blue Pants</
td
>
<
td
>${param.bluePants}</
td
>
<
td
>${bluePantsPrice}</
td
>
<
td
>${param.bluePants * bluePantsPrice}</
td
>
</
tr
>
<
tr
>
<
td
>Red Hats</
td
>
<
td
>${param.redHats}</
td
>
<
td
>${redHatPrice}</
td
>
<
td
>${param.redHats * redHatPrice}</
td
>
</
tr
>
<
tr
>
<
td
>Blue Jackets</
td
>
<
td
>${param.blueJackets}</
td
>
<
td
>${blueJacketPrice}</
td
>
<
td
>${param.blueJackets * blueJacketPrice}</
td
>
</
tr
>
<
tr
>
<
td
>Green Socks</
td
>
<
td
>${param.greenSocks}</
td
>
<
td
>${greenSocksPrice}</
td
>
<
td
>${param.greenSocks * greenSocksPrice}</
td
>
</
tr
>
</
table
>
<
div
>
Total Price: $${finalPrice}
<
c:if
test="${discount > 0}">
(Discount Applied: $${discount})
</
c:if
>
</
div
>
</
c:if
>
</
body
>
</
html
>