This sample midterm contains the kinds of questions that will be on the actual midterm. It is much longer than the midterm will be. At least one question on the midterm will be all but identical to one here.
We will not post solutions to the sample midterm problems because, in our experience, people will be tempted to look at the solution before completely doing the problem. If anyone wishes to check their answers, they may give us a paper copy for review.
We will also answer questions by email, generally by giving hints or asking leading questions back.
Bag::contains, assuming Bag has the following fields:private int _count; private Coin contents[CAPACITY];Fill the code in the following skeleton:
private class Node {
public Coin data;
public Node next;
public Node(Coin c, Node n) { data = c; next = n; }
}
private Node head;
public Bag() { head = null; }
116 public void insert(Disk element)
117 {
118 ensureCapacity(2*contents.length+1);
119
120 ++manyItems;
121
122 if (currentIndex == manyItems) {
123 contents[currentIndex] = element;
124 } else if (currentIndex == 0) {
125 for (int i=manyItems; i > 0; --i) {
126 contents[i] = contents[i-1];
127 }
128 } else {
129 for (int i=currentIndex; i < manyItems; ++i) {
130 contents[i+1] = contents[i];
131 }
132 }
133
134 contents[currentIndex] = element;
135
136 }
java.lang.ArrayIndexOutOfBoundsException: 1 at edu.uwm.cs351.DiskSeq.insert(DiskSeq.java:126) at Driver.testDiskSeq(Driver.java:182) at Driver.main(Driver.java:27) Initial tests Passed 112 tests. Failed 1 test.Your friend says ``Great! I failed only 1 out of 113 tests!'' You gently tell them ...[what?]
OutOfMemoryError. What is this error?
Why did the driver not catch it?