CS计算机代考程序代写 Java package programmingexample3;

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 implements Hamper {

private ArrayList> counts;

/**
* Create a new empty hamper.
*/
public ArrayListItemHamper() {
this.counts = new ArrayList>();
}

private Count getCount(Object o) {
for (Count c : counts)
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 c = getCount(e);
if (c != null) {
c.incrementCount(n);
} else if (n > 0) {
counts.add(new Count(e, n));
}
}

@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 c = getCount(o);
if (c != null)
return c.getCount();
return 0;
}

@Override
public int size() {
// TODO implement this
return 0;
}

@Override
public Hamper sum(Hamper hamper) {
// TODO implement this
return null;
}

@Override
public Iterator> 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 can be equal to a ArrayListItemHamper if they both only contain fruit.
* 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();
}
}