-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.9 A Prices
32 lines (25 loc) · 1 KB
/
2.9 A Prices
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.Scanner;
import java.text.NumberFormat;
public class Price
{
public static void main(String args[])
{
final double TAX_RATE = 0.06;
int quantity;
double subtotal, tax, totalCost, unitPrice;
Scanner scan = new Scanner (System.in);
System.out.print("Enter the quantity: ");
quantity = scan.nextInt();
System.out.print("Enter the unit price: ");
unitPrice = scan.nextDouble();
subtotal = quantity * unitPrice;
tax = subtotal * TAX_RATE;
totalCost = subtotal + tax;
NumberFormat money = NumberFormat.getCurrencyInstance();
NumberFormat percent = NumberFormat.getPercentInstance();
System.out.println("Subtotal: " + money.format(subtotal));
System.out.println("Tax: " + money.format(tax) + " at "
+ percent.format(TAX_RATE));
System.out.println("Total: " + money.format(totalCost));
}
}