X791: 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. You can assume anEntry is not null.

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.