Question
12. Write a complete method from the implementation perspective called getSomeEntry(). The method will be in the ArrayBag class. ArrayBag implements BagInterface using an array.
12. Write a complete method from the implementation perspective called getSomeEntry(). The method will be in the ArrayBag class.
ArrayBag implements BagInterface using an array.
The method returns an unspecified entry of the ArrayBag. You can decide which entry to return.
Be sure to account for all possible times when the method could be invoked. Your code should not crash.
The method header is:
public T getSomeEntry()
For this question, you are writing code at the implementation level. This means you have access to the private instance data variables:
private T[] bag private int numberOfEntries
You can assume the following methods are already implemented:
public boolean add(T newEntry) public boolean isEmpty() public boolean contains(T anObject) public T remove() public boolean remove(T anEntry) public int getFrequencyOf(T anEntry) public int getCurrentSize() public void clear()
19.
Write a complete method to traverse a linked list of Integers and count the number of even numbers on the list. You are given the first node in the list. The method header is:
public static int countEvens(Nodenode)
You can assume the data and next fields of the Node class are public.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started