Example - SalesTax.java, salestax.php, salestax.htm c:\program files\apache group\apache2\htdocs\test\salestax.java. import java.util.*;import java.text.*;public class SalesTax{ private double tax = 0.0; private double price = 0.0; private
Example - SalesTax.java, salestax.php, salestax.htm
c:\program files\apache group\apache2\htdocs\test\salestax.java.
import java.util.*;
import java.text.*;
public class SalesTax
{
private double tax = 0.0;
private double price = 0.0;
private double salesTax = 0.0;
public SalesTax()
{}
public String SalesTax(double price, double salesTax)
{
tax = price * salesTax;
NumberFormat nf = null;
nf = NumberFormat.getCurrencyInstance();
String priceOut = nf.format(price);
String taxOut = nf.format(tax);
nf = NumberFormat.getPercentInstance();
String salesTaxOut = nf.format(salesTax);
String str = "Sales Tax of " + salesTaxOut +
" on " + priceOut + " equals " + taxOut + ".";
return str;
}
}
C:\Program Files\Apache Group\Apache2\htdocs\test\salestax.php
<?php
if (isset($_POST["submit"]))
{
java_require('http://localhost/test/SalesTax.jar');
$salesTax = new Java("SalesTax");
$price = (double) $_POST["price"];
$tax = (double) $_POST["tax"];
echo (String) $salesTax->SalesTax($price, $tax);
}
?>
C:\Program Files\Apache Group\Apache2\htdocs\test\salestax.htm.
<html> <head> <title></title> </head> <body> <form action="salestax.php" method="post"> Price: ($)<br/> <input type="text" name="price" size="15" maxlength="15"><br/> Tax Rate: (0.1 for 10%)<br/> <input type="text" name="tax" size="15" maxlength="15"><br/> <input type="submit" name="submit" value="Calculate!"> </form> </body> </html>


PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号