Java 未正确计算成本和折扣

Java 未正确计算成本和折扣,java,Java,我的输出有问题。每次我运行程序时,它都没有给我正确的输出。这就是我到目前为止所做的: public class ItemSales { private int sold, bulkQuantity; private double cost, profit, discount, bulkDiscount; public ItemSales(int bq, double bd, double c) { bulkQuantity = bq; bulkDiscount = b

我的输出有问题。每次我运行程序时,它都没有给我正确的输出。这就是我到目前为止所做的:

public class ItemSales {
  private int sold, bulkQuantity;
  private double cost, profit, discount, bulkDiscount;
  public ItemSales(int bq, double bd, double c) {
    bulkQuantity = bq;
    bulkDiscount = bd;
    cost = c;
  }
  public void setCost(double c) {
    cost = c;
  }
  public void setBulkQuantity(int bq) {
    bulkQuantity = bq;
  }
  public void setDiscountPercentage(double bd) {
    bulkDiscount = bd;
  }
  public double getCost() {
    return cost;
  }
  public void registerSale(int sold) {
    if (sold > bulkQuantity) {
      cost = cost * (bulkDiscount / 100);
      this.sold += sold;
    }
    //this.sold+=sold;
  }
  public double getDiscountPercentage() //gets the discount the customer receives from buying in bulk
  {
    return discount;
  }
  public void displaySales() {
    getCost();
    double totalAmount = cost * sold;
    System.out.println("Total number of items sold: " + sold);
    System.out.println("Total sales: $" + totalAmount);
    System.out.println("Total discount: $" +
      getDiscountPercentage());
  }
}
第一个错误是:每次我试图将物品的成本乘以售出的物品(
cost*selled
)时,它都没有做任何事情

第二:它只是返回项目的成本:
cost


第三:折扣根本不适用(我不知道为什么)。我想知道的是,为了让程序正常运行,到底需要改变什么。我已经做了多次测试和更改,但我仍然处于与以前相同的位置。

您必须将程序的输入提供给我们,以便我们能够正确地提供帮助。但是,根据您的问题,您是否尝试在正确给出所有输入并进行所有计算后调用
displaySales()
函数


我向eclipse打开了您的代码,以便大致检查您所做的工作。你会从阅读中受益。

一个常见的错误:
javascript
java
不同于
j
刚刚解决了这个问题。