Я пытаюсь сделать на задании Java, а сценарий заключается в следующем: < /p>
Налог с продаж в размере 7% взимается на все потребляемые товары и услуги. Также обязательно, что все цены должны включать налог с продаж. Например, если товар имеет цену в 107 долл. США, фактическая цена составляет 100 долл. США, а 7 долл. США поступают в налог с продажи. цена включена налогом (как «двойной»); Вычислить фактическую цену и налог с продаж (в «двойном»); и распечатайте результаты, округленные до 2 десятичных знаков. Программа должна прекращаться в ответ на вход -1; и распечатать общую цену, общую фактическую цену и общий налог с продаж.
Введите · Инклюзивные налоговые p> фактическая цена · IS: $ 100,00 < /p>
Продажи · налог · IS: $ 7,00 < /p>
Мой расчет показывает это : < /p>
Введите цену, включенную налогом в долларах (или -1 до конца): 107 < /p>
Фактическая цена $ 99,51 < /p>
Налог с продаж: $ 7,49 < /p>
Я не уверен, что не так с моим кодированием. < /p>
import java.util.Scanner;
public class SalesTax{
public static void main(String[] args) {
// Declare constants
final double SALES_TAX_RATE = 0.07;
final int SENTINEL = -1; // Terminating value for input
// Declare variables
double price, actualPrice, salesTax; // inputs and results
double totalPrice = 0.0, totalActualPrice = 0.0, totalSalesTax = 0.0; // to accumulate
// Read the first input to "seed" the while loop
Scanner in = new Scanner(System.in);
System.out.print("Enter the tax-inclusive price in dollars (or -1 to end): ");
price = in.nextDouble();
while (price != SENTINEL) {
// Compute the tax
salesTax = SALES_TAX_RATE * price;
actualPrice = price - salesTax;
// Accumulate into the totals
totalPrice = actualPrice + salesTax;
totalActualPrice = actualPrice + actualPrice;
totalSalesTax = salesTax + salesTax;
// Print results
System.out.println("Actual price is $" + String.format("%.2f",actualPrice));
System.out.println("Sales Tax is: $" + String.format("%.2f",salesTax));
// Read the next input
System.out.print("Enter the tax-inclusive price in dollars (or -1 to end): ");
price = in.nextDouble();
// Repeat the loop body, only if the input is not the sentinel value.
// Take note that you need to repeat these two statements inside/outside the loop!
}
// print totals
System.out.println("Total price is: " + String.format("%.2f",totalPrice));
System.out.println("Total Actual Price is: " + String.format("%.2f",totalActualPrice));
System.out.println("Total sales tax is: " + String.format("%.2f",totalSalesTax));
}
}
< /code>
Любая помощь будет оценена. Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/600 ... -the-price