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

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

2016 D Term Grading ] [ 2016 D Term Group Project ] [ 2016 D Term Paper Guidelines ] [ 2016 D Term Presentation Guidelines ] [ 2016 D Term Reading Guidelines ] [ Up: 2016 D Term ]

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

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

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

if ( amountString != null && ! amountString.matches ( "^[0-9+-+.]+$" ) )
{
	amountString = amountString.replaceAll ( "[e.]", "" );
}
if ( discountRateString != null && ! discountRateString.matches ( "^[0-9+-+.]+$" ) )
{
	discountRateString = discountRateString.replaceAll ( "[e.]", "" );
}
if ( taxRateString != null && ! taxRateString.matches ( "^[0-9+-+.]+$" ) ) 
{
	taxRateString = taxRateString.replaceAll ( "[e.]", "" );
}

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

try
{

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

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

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

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

That was naughty. Please use numbers.

<% } 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) %>

by: Keith A. Pray
Last Modified: March 5, 2017 5:02 PM
© 2017 - 1975 Keith A. Pray.
All rights reserved.

Current Theme: 

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