12. Write a complete method from the implementation perspective called getSomeEn
ID: 3733464 • Letter: 1
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.
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:
For this question, you are writing code at the implementation level. This means you have access to the private instance data variables:
You can assume the following methods are already implemented:
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:
You can assume the data and next fields of the Node class are public.
Explanation / Answer
Please find my answer for Q19.
Please repost others in separate post.
public static int countEvens(Node<Integer> node) {
int count = 0;
while(node != null) {
count++;
node = node.next;
}
return count;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.