Question: This code was made using JAVA. Modify the following code so that the user may repeat this as many times as they wish using a
This code was made using JAVA.
Modify the following code so that the user may repeat this as many times as they wish using a sentinel value loop. Use a sentinel value loop. Use a sales amount of 0 as the sentinel value.Count the transactions, and total the amount due.
import java.util.*; import java.text.DecimalFormat;
public class Salestax2 { public static final double TAXRATE = 0.06, discoutrate1 = 0.05, discoutrate2 = 0.1, discoutrate3 = 0.15; public static void main(String[] args) {
double amount, tax, subtotal, discount;
DecimalFormat df = new DecimalFormat("#0.00"); Scanner input = new Scanner(System.in);
System.out.println("Total due calculation program"); System.out.print("Enter the sales amount: $ ");
amount = input.nextDouble(); if (amount < 100){ discount = amount * discoutrate1; } else if(amount >=100 && amount<250){ discount = amount * discoutrate2; } else{ discount = amount * discoutrate3; } tax = (amount - discount) * TAXRATE; subtotal = amount - discount + tax; System.out.println();
System.out.println("Bill Summary: ");
System.out.println("Sales amount: $" + df.format(amount));
System.out.println("Discount: $" + df.format(discount));
System.out.println("tax (at 6.00%): $" + df.format(tax));
System.out.println("Total due: $" + df.format(subtotal));
input.close(); // optional
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
