29.2k views
19 votes
Please answer in Java

Sale! During a special sale at a store, a 10% discount is taken off of purchases over $10.00.
Create an application that prompts the user for the dollar amount of purchases and then
returns the discounted price, if any. The program should neatly display the subtotal before
the discount, the amount of money discounted (if any), the HST applied to the subtotal and
finally the total. The program should be able to handle negative numbers and give an
appropriate message.
Sample Run #1:
Enter the purchase amount: 9.45
No discount applied.
Subtotal: $9.45
HST: $1.23
Total: $10.68
Sample Run #2
Enter the purchase amount: 15.00
10% discount applied.
Subtotal: $15.00
Discount: - $1.50
HST: S1.76
Total: $15.26

User Ceisc
by
6.4k points

1 Answer

6 votes

Answer:

Scanner keyboard = new Scanner(System.in);

double discount = 0;

double productPrice;

double subTotal;

double salesTax;

double saleTotal;

System.out.printf("Enter the purchase amount:");

productPrice = keyboard.nextDouble();

if (productPrice > 10) {

discount = 10;

}

System.out.println( + discount + "% discount applied.");

subTotal = (productPrice);

salesTax = (subTotal * 0.14);

saleTotal = (subTotal + salesTax - discount );

System.out.printf("Subtotal: $%5.2f\\", subTotal);

System.out.printf("Discount; -$%5.2f\\", productPrice - discount);

System.out.printf("HST: $%5.2f\\", salesTax);

System.out.printf("Total: $%5.2f\\", saleTotal + salesTax);

}

}

Step-by-step explanation: