package programmingexample3;
import java.util.ArrayList;
import java.util.Iterator;
/**
* A hamper implemented using an ArrayList.
*
* @author Matthew Perry
*
* @invariant for all c in counts, c.getCount() > 0
*
* @param
*/
public class ArrayListItemHamper
private ArrayList
/**
* Create a new empty hamper.
*/
public ArrayListItemHamper() {
this.counts = new ArrayList
}
private Count
for (Count
if (c.getElement().equals(o))
return c;
return null;
}
@Override
public void add(E e) {
add(e,1);
}
@Override
public void add(E e, int n) {
Count
if (c != null) {
c.incrementCount(n);
} else if (n > 0) {
counts.add(new Count
}
}
@Override
public void remove(E e) {
remove(e, 1);
}
@Override
public void remove(E e, int n) {
// TODO implement this
}
@Override
public int count(Object o) {
Count
if (c != null)
return c.getCount();
return 0;
}
@Override
public int size() {
// TODO implement this
return 0;
}
@Override
public Hamper
// TODO implement this
return null;
}
@Override
public Iterator
return counts.iterator();
}
/**
* For this method, hampers should be the same class to be equal (ignore the generic type component). For example, a CreativeHamper cannot be equal to a FruitHamper,
* And a FruitHamper cannot be equal to an ArrayListItemHamper
* However an ArrayListItemHamper
* HINT: use getclass() to compare objects.
*/
@Override
public boolean equals(Object o) {
// TODO implement this
return false;
}
/**
*
* @return price of the hamper – for ArrayListItemHamper, this should be the sum of the prices of items with each price multiplied by the number of times that item occurs
*/
@Override
public int getPrice() {
// TODO implement this
return 0;
}
@Override
public String toString(){
return counts.toString();
}
}