X791: ArrayBag GetFrequencyOf

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

x
 
1
public static final class ArrayBag<T> implements BagInterface<T> {
2
    private T[] contents;
3
    private static final int MAX = 25;
4
    private int numberOfEntries;
5
6
    public ArrayBag() {
7
        T[] tempBag = (T[])new Object[MAX];
8
        contents = tempBag;
9
        numberOfEntries = 0;
10
    }
11
  }

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:

xxxxxxxxxx
4
 
1
public int getFrequencyOf(T anEntry) {
2
    
3
}
4
Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.