Hello, im having problem with my output =/
Everytime i run my program is not giving me
the right output so, this is my assaigment.

Consider a class that keeps track of the sales of an item. An object of this class will have the attributes:

Number Sold
Total Sales (In Dollars)
Total Discounts
Cost per item
Bulk Quantity
Bulk discount percentage

And the following methods:

ItemSales() - Default constructor

ItemSales(double itemCost) - Constructor that initializes the itemCost.

ItemSales(double itemCost, int bulkQuantity, double discountPecentage) - Constructor that initializes itemCost, bulkQuatity and discoutPercentage.

ItemSales(int bulkQuantity, double discountPercentage) - Constructor the initializes bulkQuatity and discoutPercentage.

registerSale(n) Records the sale of n items. If n is equal to or larger than the bulk quatity, the cost per item will be reduced by the bulk discount.

displaySales() Displays the number sold, the total sales, and total discount.
equals(ItemSales otherItem) - Compare two ItemSales objects for equality. They will be considered equal if all the attributes are equal.

Implement get, and set methods for all attributes.

Implement this class in Java and write another class to test it. Make sure you test all the possibilities.

and here is the code:

 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);



public double getDiscountPercentage() //gets the discount the customer receives from buying in bulk
     return discount;

public void displaySales() {

    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());



The first error is: that everytime i try to multiply the cost of the item times the items sold ( cost * sold)
is not doing nothing.

second: it's just returning the cost of the item; cost
third: the discount is not even applying (I don't know why)

The program may look wear but I just been trying to solve it and i changed it many times.

This is the Demo:

public class ItemSalesDemo
public static void main(String[] args)
    ItemSales sale = new ItemSales(4, 10, 2.50); 


3 Years
Discussion Span
Last Post by stultuske

well, have you debugged, added some prints at least?
the discount is not changing because: you never update the value.

could you be a bit more specific on what you expect as result?

Edited by stultuske

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.