Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This code was made using JAVA. Modify the following code so that the user may re

ID: 3591091 • Letter: T

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 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

       }

       }

Explanation / Answer

Salestax2.java

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;
int numberOfTransactions = 0;
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();
while(amount!=0) {
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));
numberOfTransactions++;
System.out.print("Enter the sales amount: $ ");
amount = input.nextDouble();
}
System.out.println("Number of transactions: "+numberOfTransactions);
input.close(); // optional
}
  
}
Output:

Total due calculation program
Enter the sales amount: $ 1000

Bill Summary:
Sales amount: $1000.00
Discount: $150.00
tax (at 6.00%): $51.00
Total due: $901.00
Enter the sales amount: $ 100

Bill Summary:
Sales amount: $100.00
Discount: $10.00
tax (at 6.00%): $5.40
Total due: $95.40
Enter the sales amount: $ 200

Bill Summary:
Sales amount: $200.00
Discount: $20.00
tax (at 6.00%): $10.80
Total due: $190.80
Enter the sales amount: $ 300

Bill Summary:
Sales amount: $300.00
Discount: $45.00
tax (at 6.00%): $15.30
Total due: $270.30
Enter the sales amount: $ 0
Number of transactions: 4