1

我必须编写一个程序,要求用户输入购买的包裹数量。然后程序应显示折扣金额和折扣后的购买总额。我是围绕这个程序设计的..

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 没有符号。因此,如果有人可以帮助我找出我的错误,我将不胜感激。

4

2 回答 2

8

阅读错误信息。您从未声明过priceBfDisc; 你宣布priceBfDiscount.

于 2013-10-13T15:27:56.213 回答
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;
于 2013-10-13T15:29:45.857 回答