我必须编写一个程序,要求用户输入购买的包裹数量。然后,程序应显示折扣后的折扣金额和购买总金额。我是围绕这个程序设计的。
import java.util.Scanner;
public class softwareSales
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
double Package = 99, discount, priceBfDiscount, discountPrice, totalPrice;
int quantity;
System.out.println("This is a software sales program");
System.out.println("Enter number of packages");
quantity = input.nextInt();
System.out.println("Enter price of package");
Package = input.nextDouble();
System.out.println("Enter gross price");
priceBfDiscount = input.nextDouble();
priceBfDisc = Package * quantity;
discountPrice = priceBfDisc * discount;
totalPrice = priceBfDisc - discountPrice;
System.out.println("The price before discount is $" + priceBfDisc);
System.out.println("The discount price is $" + discountPrice);
System.out.println("The total price is $" + totalPrice);
if (quantity >= 10 && quantity <= 19)
{
System.out.println("The discount is .20");
}
else if (quantity >=20 && quantity <=49)
{
System.out.println("The discount is .30");
}
else if (quantity >=50 && quantity <=99)
{
System.out.println("The discount is .40");
}
else if (quantity >=100)
{
System.out.println("The discount is .50");
}
}
我不知道错误是什么。它一直说priceBfDisc没有符号。所以,如果有人能帮我辨别我的错误,我会非常感激。
答案 0 :(得分:8)
阅读错误消息。你没有宣布priceBfDisc
;你声明了priceBfDiscount
。
答案 1 :(得分:0)
double Package = 99, discount, priceBfDiscount, discountPrice, totalPrice;
除了priceBfDics
不匹配的错误之外,这就是您的问题所在。
您需要声明所有这些变量
//Either like this
double packageCost;
double discount;
double priceBfDiscount;
double discountPrice,
double total;
// Or like this
double packageCost,discount, priceBfDiscount, discountPrice, total;