This Problem Set Is Due By 11:59 PM on November 3, 2013

  1. Item Sales (10 points)

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

    • numberSold - An int that holds the total number of items sold.
    • totalSales - A double that holds the total amount of sales in dollars.
    • totalDiscounts - A double that holds the total amount of discounts given in dollars.
    • itemCost - A double that holds the cost of each item in dollars.
    • bulkQuantity - An int that holds the minimum number of items that must be bought in one sale in order for the bulkDiscountPercent to apply.
    • bulkDiscountPercent - A double that indicates the discount percentage that a customer receives when they purchase a number of items greater than or equal to bulkQuantity.

    And the following methods:

    • ItemSales() - Default constructor
    • ItemSales(double itemCost) - Constructor that initializes the itemCost.
    • ItemSales(double itemCost, int bulkQuantity, double bulkDiscountPecent) - Constructor that initializes itemCost, bulkQuatity and discoutPercentage.
    • ItemSales(int bulkQuantity, double bulkDiscountPercent) - 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.

    Name these programs ItemSales & ItemSalesDemo
    Place both classes in the edu.cuny.lehman.cmp326 package.

  2. VariableArray (20 points)

    Consider a class that maintains an array of int's. The class has the following private attributes:

    • INITIAL_ARRAY_SIZE - a constant set to 10
    • ARRAY_EXPAND - a constant set to 20
    • myInts - an array of int's that is initialized to INITIAL_ARRAY_SIZE with all the entries set to zero.
    • currentInt - an int indicating the index of the current int. This attribute should be initialized to 0, the location of where the next integer will be added.

    And the following methods:

    • VariableArray() - Default constructor that creates myInts with INITIAL_ARRAY_SIZE entries, all initialized to zero.
    • VariableArray(int initialArraySize) - Constructor that creates myInts with the specified initalArraySize entries, all initialized to zero.
    • VariableArray(int[] integerArray) - Constructor that creates myInts with the enough space to hold the given integerArray array. all entries are initialized from the given integerArray array. Make sure to also initialize currentInt appropriately.
    • addInt(int integer) - Add integer to myInts and update currentInt. If there is no room in myInts, the array will have to be resized by adding ARRAY_EXPAND entries.
    • addInts(int[] integerArray) - Add the given intergerArray to myInts and update currentInt. If there is not enough room in myInts, the array will have to be resized by adding the appropriate multiple of ARRAY_EXPAND entries.
    • deleteInt(int index) - Delete the integer at the given index. Make sure to compress myInts and update currentInt. You must also verify that the given index exists in myInts.
    • deleteInts(int index, int count) - Delete the integers count starting at the given index. Make sure to compress myInts and update currentInt. You must also verify that the given index exists in myInts and that there are count entries starting from there.
    • equals(VariableArray otherArray) - Compare two VariableArrays objects for equality. They will be considered equal, if and only if both have the same number of integers and all their entries are equal.
    • getIntAt(int index) - This method returns the integer located at the given index. This method must verify that the given index is before currentInt and within the bounds of the size of myInts. In case of an error, this method should return -99999.
    • showAll() - This method prints out myInts and currentInt.

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

    Name these programs VariableArray & VariableArrayDemo
    Place both classes in the edu.cuny.lehman.cmp326 package.

Please submit the completed assignment on Blackboard by attaching all your .java files. Make sure to attach all your programs to each submission.