Class IntegerBag

java.lang.Object
  extended by IntegerBag

public class IntegerBag
extends java.lang.Object

Objects of the class IntegerBag are simple representations of a set of integers supporting some basic mathematical operations (min, max, sum, and product).


Constructor Summary
IntegerBag(java.lang.Integer[] numbers)
          Creates a new IntegerBag instance having the (non-null) integers in the given array in the bag
 
Method Summary
 java.lang.Integer max()
          Calculate the largest number in this bag according to Integer.compareTo
 java.lang.Integer min()
          Calculate the smallest number in this bag according to Integer.compareTo
 java.lang.Integer product()
          Calculate the product of the numbers in this bag.
 int size()
          Number of integers in this bag.
 java.lang.Integer sum()
          Calculate the sum of the numbers in this bag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntegerBag

public IntegerBag(java.lang.Integer[] numbers)
Creates a new IntegerBag instance having the (non-null) integers in the given array in the bag

Parameters:
numbers - Array of values to include in the bag
Method Detail

size

public int size()
Number of integers in this bag.

Returns:
Number of integers in this bag.

max

public java.lang.Integer max()
Calculate the largest number in this bag according to Integer.compareTo

Returns:
The largest number in this bag
Throws:
java.lang.IllegalStateException - if there are no numbers

min

public java.lang.Integer min()
Calculate the smallest number in this bag according to Integer.compareTo

Returns:
The smallest number in this bag
Throws:
java.lang.IllegalStateException - if there are no numbers

sum

public java.lang.Integer sum()
Calculate the sum of the numbers in this bag.

Returns:
Sum of the numbers in this bag

product

public java.lang.Integer product()
Calculate the product of the numbers in this bag.

Returns:
Product of the numbers in this bag