編寫一個程序,輸入三件物品的名稱、數量和價格。名稱可能包含空格。輸出稅率為 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; }}
添加回答
舉報
0/150
提交
取消