WPI Social Implications Of Computing
Course Documents
Assignments
Past
                                          
Printer Friendly Version
Assignments

Intro ] [ Code Test ] [ Code Test.jsp ] [ Presentation Template.pptx ]

Due Dates ] [ Grading ] [ Group Project ] [ Paper Guidelines ] [ Presentation Guidelines ] [ Reading Guidelines ] [ Up: 2014 D Term Archive ]

<%@ page import="java.text.NumberFormat" %>
<%
String amountString = request.getParameter ( "amount" );

String discountRateString = request.getParameter ( "discountRate" );

String taxRateString = request.getParameter ( "taxRate" );

double amount = 0.0;
double discountRate = 0.0;
double taxRate = 0.0;

try
{

if ( amountString == null || amountString == "" )
{
   amountString = "";
}
else
{
   amount = Double.valueOf ( amountString ).doubleValue();
}

if ( discountRateString == null || discountRateString == "" )
{
   discountRateString = "";
}
else
{
   discountRate = Double.valueOf ( discountRateString ).doubleValue();
}

if ( taxRateString == null || taxRateString == "" )
{
   taxRateString = "";
}
else
{
   taxRate = Double.valueOf ( taxRateString ).doubleValue();
}

}
catch ( NumberFormatException ex )
{
	amountString = "";
	discountRateString = "";
	taxRateString = "";
%>

That was naughty. Please use numbers and fill in all fields.

<% } double discount = amount * discountRate; double total = amount - discount; double tax = total * taxRate; double taxedTotal = tax + total; NumberFormat numberFormat = NumberFormat.getCurrencyInstance(); // let's print out what example this is String submitString = request.getParameter ( "submit" ); %>

Enter Amount

Enter Discount Rate

Enter Tax Rate



Subtotal: <%= numberFormat.format(amount) %>
Discount: <%= numberFormat.format(discount) %>
Total : <%= numberFormat.format(total) %>
Tax : <%= numberFormat.format(tax) %>
Tax+Total: <%= numberFormat.format(taxedTotal) %>

Keith A. Pray
Last Modified: August 18, 2014 11:07 PM
© 2014 - 1975 Keith A. Pray.
All rights reserved.

Current Theme: 

Kapowee Hosted | Kapow Generated in 0.008 second | XHTML | CSS