Напишите программу, которая вводит название, количество и цену трех предметов.Имя может содержать пробелы.Вывести счет с налоговой ставкой 6,25%.Все цены должны быть выведены с точностью до двух знаков после запятой.Счет должен быть отформатирован в столбцы с 30 символами для названия, 10 символов для количества, 10 символов для цены и 10 символов для итога.Пример ввода и вывода показан следующим образом:
import java.util.Scanner;
public class ProjectLab {
public static final double SALES_TAX = 8.625;
public static void main(String[]args) {
Scanner input = new Scanner(System.in);
String item1, item2, item3;
int quantity1, quantity2, quantity3;
double price1, price2, price3;
//Input for the first Item
System.out.println("Input the name of item 1: ");
item1 = input.nextLine();
System.out.println("Input quantity of item 1: ");
quantity1 = input.nextInt();
System.out.println("Input price of item 1: ");
price1 = input.nextDouble();
String junk = input.nextLine(); //Junk Line
//Input for the second Item
System.out.println("Input name of item 2: ");
item2 = input.nextLine();
System.out.println("Input quantity of item 2: ");
quantity2 = input.nextInt();
System.out.println("Input price of item 2: ");
price2 = input.nextDouble();
String junk2 = input.nextLine(); //Junk line 2
//Input for the third item
System.out.println("Input name of item 3: ");
item3 = input.nextLine();
System.out.println("Input quantity of item 3: ");
quantity3 = input.nextInt();
System.out.println("Input price of item 3: ");
price3 = input.nextDouble();
double subtotal1 = price1 * quantity1;
double subtotal2 = price2 * quantity2;
double subtotal3 = price3 * quantity3;
System.out.println("Your bill: ");
System.out.println("Item Quantity Price Total");
System.out.println(item1 + " " + quantity1 + " " + price1 + " " + subtotal1 );
System.out.println(item2 + " " + quantity2 + " " + price2 + " " + subtotal2 );
System.out.println(item3 + " " + quantity3 + " " + price3 + " " + subtotal3 );
double finalSubtotal = (subtotal1 + subtotal2 + subtotal3);
System.out.printf("Subtotal %.2f \n" , finalSubtotal);
double tax = (finalSubtotal / SALES_TAX);
System.out.printf("8.265% Sales tax %.2f\n ", tax);
double total = tax + finalSubtotal;
System.out.printf("Total %.2f ", total);
}
}
Вывод:
Input the name of item 1:
Gummi Bears
Input quantity of item 1:
10
Input price of item 1:
1.29
Input name of item 2:
Monster Energy
Input quantity of item 2:
3
Input price of item 2:
2.97
Input name of item 3:
Ruffles Chips
Input quantity of item 3:
20
Input price of item 3:
1.49
Your bill:
Item Quantity Price Total
Gummi Bears 10 1.29 12.9
Monster Energy 3 2.97 8.91
Ruffles Chips 20 1.49 29.8
Subtotal 51.61
Exception in thread "main" java.util.FormatFlagsConversionMismatchException: Conversion = s, Flags =
at java.util.Formatter$FormatSpecifier.failMismatch(Formatter.java:4298)
at java.util.Formatter$FormatSpecifier.checkBadFlags(Formatter.java:2997)
at java.util.Formatter$FormatSpecifier.checkGeneral(Formatter.java:2955)
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2725)
at java.util.Formatter.parse(Formatter.java:2560)
at java.util.Formatter.format(Formatter.java:2501)
at java.io.PrintStream.format(PrintStream.java:970)
at java.io.PrintStream.printf(PrintStream.java:871)
at ProjectLab.main(ProjectLab.java:65)