Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6344a47

Browse files
Sales Tax
1 parent c407cab commit 6344a47

File tree

1 file changed

+46
-0
lines changed
  • Programming-Challenges/Fundamentals/src/com/challenges

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Write a program that will ask the user to enter the amount of a purchase.
3+
The program should then compute the state and county sales tax.
4+
Assume the state sales tax is 4 percent and the county sales tax is 2 percent.
5+
The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax,
6+
and the total of the sale (which is the sum of the amount of purchase plus the total sales tax).
7+
8+
Hint: Use the value 0.02 to represent 2 percent, and 0.04 to represent 4 percent.
9+
*/
10+
11+
package com.challenges;
12+
13+
import java.util.Scanner; // Import the Scanner Class
14+
15+
public class SalesTax {
16+
public static void main(String [] args) {
17+
18+
// Declare Variables
19+
final double STATE_TAX = 0.04;
20+
final double COUNTY_TAX = 0.02;
21+
double purchaseAmount;
22+
double countyTax;
23+
double stateTax;
24+
double totalTax;
25+
double totalSale;
26+
27+
Scanner scanner = new Scanner(System.in); // Creating Scanner Object
28+
29+
System.out.print("Please enter the purchase amount: ");
30+
purchaseAmount = scanner.nextDouble(); // Taking Purchase Amount as Input
31+
32+
countyTax = COUNTY_TAX * purchaseAmount; // Calculating Country Tax
33+
stateTax = STATE_TAX * purchaseAmount; // Calculating State Tax
34+
35+
totalTax = countyTax + stateTax; // Calculating Total Tax
36+
37+
totalSale = purchaseAmount + totalTax; // Calculating Total Sale Amount
38+
39+
System.out.println("Amount of purchase: $" + purchaseAmount);
40+
System.out.println("State Sales Tax: $" + stateTax);
41+
System.out.println("County Sales Tax: $" + countyTax);
42+
System.out.println("Total Sales Tax: $" + totalTax);
43+
System.out.println("Total Sale: $" + totalSale);
44+
45+
}
46+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /