尝试编写一个 Java 程序来满足这一点: Duke Shirts 以每件 24.95 美元的价格出售 Java T 恤,但以下数量可能有折扣: 1 或 2 件衬衫,无折扣,总运费为 10.00 美元 3-5 件衬衫,折扣为 10 %,总运费为 8.00 美元 6-10 件衬衫,折扣为 20%,总运费为 5.00 美元 11 件或更多衬衫,折扣为 30%,运费免费 编写一个 Java 程序,提示用户输入所需衬衫的数量。然后程序应该打印衬衫的扩展价格、运费和订单的总成本。在适当的地方使用货币格式。
这是我的代码:
import java.lang.Math;
import java.util.Scanner;
public class Excercise2_3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("How many shirts do you need?");
double shirts = input.nextInt();
if (shirts <= 2)
System.out.printf("The extended cost is : $%.2", (shirts * 24.95));
System.out.printf("The shipping charges are $10.00");
System.out.printf("The total cost is : $%.2", (shirts * 24.95) + 10);
if (shirts > 2 && shirts <= 5)
System.out.printf("The extended cost is : $%.2", ((shirts * 24.95)*.10));
System.out.printf("The shipping charges are $8.00");
System.out.printf("The total cost is : $%.2", ((shirts * 24.95)*.10) + 8);
if (shirts > 5 && shirts <= 10)
System.out.printf("The extended cost is : $%.2", ((shirts * 24.95)*.20));
System.out.printf("The shipping charges are $5.00");
System.out.printf("The total cost is : $%.2", ((shirts * 24.95)*.20) + 5);
if (shirts > 10)
System.out.printf("The extended cost is : $%.2", ((shirts * 24.95)*.00));
System.out.printf("Shipping is free!");
System.out.printf("The total cost is : $%.2", ((shirts * 24.95)*.30));
}
}
谁能解释为什么它不能正确编译?谢谢!