import java.util.Scanner;
import java.text.NumberFormat;
import java.math.*;
public class invoiceApplication {
public static void main(String[] args) {
System.out.println("Welcome to the Invoice Total Calculator");
System.out.println();
Scanner sc = new Scanner(System.in);
final double SALES_TAX_PCT = .05;
String choice = "y";
while (choice.equalsIgnoreCase("y"))
{
//get the input from user
System.out.print("Enter subtotal: ");
double subtotal = sc.nextDouble();
//calculate the results
double discountPercent = 0.0;
if (subtotal >= 500)
discountPercent = .25;
else if (subtotal >= 200)
discountPercent = .2;
else if (subtotal >= 100)
discountPercent = .1;
else
discountPercent = 0.0;
double discountAmount = discountPercent * subtotal;
double totalBeforeTax = subtotal - discountAmount;
double salesTax = totalBeforeTax * SALES_TAX_PCT;
double total = totalBeforeTax - salesTax;
// format and display the results
NumberFormat currency = NumberFormat.getCurrencyInstance();
NumberFormat percent = NumberFormat.getPercentInstance();
String message =
"Discount percent: " + percent.format(discountPercent) + "\n"
+ "Discount amount: " + currency.format(discountAmount) + "\n"
+ "Total before tax: " + currency.format(totalBeforeTax) + "\n"
+ "Sales tax: " + currency.format(salesTax) + "\n"
+ "Invoice total: " + currency.format(total) + "\n";
System.out.println(message);
// see if the user wants to continue
System.out.println();
System.out.println("Continue? (y/n)");
choice = sc.next();
}
}
}