In: Computer Science
In Canada, anytime one purchases from a store, the government imposes a sales tax. In most provinces, there are two levels of sales taxes: The GST, which is a Federal tax, is set at 5% of the purchase price. Then, there is the PST, which is a Provincial tax that most provinces charge. The PST rate is dependent on the province. For instance, in British Columbia, the provincial rate is 7 % of the purchase price. You are to print the following receipt for the purchase of products in B.C. It should look similar to the following:
No. of Units: 10
Unit Price: $ 20.00
Purchase Amount: $ 200.00
Sales Taxes:
GST: $ 10.00
PST: $ 14.00
Total: $ 24.00
Total Amount: $ 224.00
Write out the code in Java such that it will accept input from the user via the terminal for the number of units and the unit price and produce the above report. Note that the report is well-formatted
import java.util.Scanner; class Main{ public static void main(String[] args) { Scanner obj = new Scanner(System.in); System.out.print("No. of Units: "); int n = obj.nextInt(); System.out.print("Unit Price: $"); double price = obj.nextDouble(); double total = price*n; System.out.println("Sales Taxes: "); double gst = (total*5)/100; System.out.printf("GST: $%.2f\n",(total*0.05)); double pst = (total*7)/100; System.out.format("PST: $%.2f\n",(total*0.07)); total += (gst+pst); System.out.println("Total Amount: $"+total); } }
OUTPUT :