X464: ArrayBag GetFrequencyOf

For this exercise, you are writing code in the following implementation of ArrayBag:

public static final class ArrayBag<T> implements BagInterface<T> {
    private T[] contents;
    private static final int MAX = 25;
    private int numberOfEntries;

    public ArrayBag() {
        T[] tempBag = (T[])new Object[MAX];
        contents = tempBag;
        numberOfEntries = 0;

Write a method getFrequencyOf that takes in a parameter anEntry This method will return the number of times a given entry appears.

For example if your bag contains (1, 1, 2, 3, 5) bag.getFrequencyOf(1) should return 2.

Your Answer:


Practice a different Java exercise


Your feedback will appear here when you check your answer.