/** SalesTax.java
*/
// required for input from keyboard
import java.util.Scanner;
// required for currency and percent formatting
import java.text.NumberFormat;
public class SalesTax {
/**
* @param args
*/
public static void main(String[] args) {
final double
TAX_RATE = 0.06; // 6% sales tax
double
subtotal, tax, totalCost; // Calculated values
// Set up
Scanner object for the keyboard
Scanner scan =
new Scanner (System.in);
System.out.print("Enter the price: ");
double price =
scan.nextDouble();
System.out.print("Enter the quantity: ");
int quantity =
scan.nextInt();
subtotal =
price * quantity;
tax = subtotal
* TAX_RATE;
totalCost =
subtotal + tax;
//
Create desired formatting objects
NumberFormat fmt1 = NumberFormat.getCurrencyInstance();
NumberFormat fmt2 = NumberFormat.getPercentInstance();
// Print
messages using formatting objects
System.out.println ("Subtotal: " + fmt1.format(subtotal));
System.out.println ("Tax: " + fmt1.format(tax) + " at "
+ fmt2.format(TAX_RATE));
System.out.println ("Total: " + fmt1.format(totalCost));
System.out.println("Total squared: " +
fmt1.format(Math.pow(totalCost,2)));
}
}