-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathState & County Tax Calculator Console
35 lines (28 loc) · 1.21 KB
/
State & County Tax Calculator Console
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
33
34
35
import java.util.Scanner;
import java.text.DecimalFormat;
public class PrestonPgm02b {
public static void main(String[] args){
// Variables
double purchasePrice = 0;
double stateTax = 0.04;
double countyTax = 0.02;
// Decimal formatting for two places
DecimalFormat df = new DecimalFormat("#.00");
// Create keyboard scanner
Scanner keyboard = new Scanner(System.in);
// Get purchase price
System.out.println("What is the cost of the item?");
purchasePrice = keyboard.nextDouble();
// Variables for calculations
double purchaseState = (purchasePrice * stateTax);
double purchaseCounty = (purchasePrice * countyTax);
double totalTax = (purchaseState + purchaseCounty);
double totalPurchase = (purchasePrice + totalTax);
// Output of purchase and taxes
System.out.println ( "The purchase price is $" + df.format(purchasePrice) + "." );
System.out.println ( "The state sales tax is $" + df.format(purchaseState) + "." );
System.out.println ( "The county tax is $" + df.format(purchaseCounty) + "." );
System.out.println ( "The total sales tax is $" + df.format(totalTax) + ".") ;
System.out.println ( "The total purchase price is $" + df.format(totalPurchase) + "." );
}
}