The questions on this sample test were extracted from an actual midterm. Because that midterm occurred later in the term (relative to this year) it covered more topics.
The actual midterm was about twice this length.
Your midterm next week will have more questions than this, as well.
The questions are provided only to give you some idea of the kinds of questions I ask: short answers, writing code, and multiple choice.
public static void modify(Bag<String> bag) {
Bag<String> newBag;
while (!bag.isEmpty()) {
String s = bag.remove();
if (!newBag.contains(s)) {
newBag.add(s);
}
}
while (!newBag.isEmpty()) {
bag.add(newBag.remove());
}
}
Suppose myBag contains "A", "B", "C", "D", "A", "E", and "D".
What does myBag contain
after modify(myBag) has been called?
Define the interface. (No comments necessary!)
Show the contents of the array after
0 1 2 3 4 5 6 7 8 9 "Anita" "Bill" "Chantal" "Djeri" "Eli" "Frank" "Gordon" / / /
remove("Bill") has been executed.
count method for the LinksBag class:
public class LinksBag<T> implements Bag<T> {
private class Node {
private Node next;
private T data;
}
private Node first;
}
The method counts how many times a given entry appears in the LinksBag object.
Do not use either toArray method,
nor any method that need to be imported,
and do not modify the contents of the bag in any way.
Note that this class does not have a numInBag field.
cur.next = first;
has been executed by putting X(s) thru old arrow(s) and adding new arrow(s).
obj,
and we want to check to see if it holds a Circle object,
the way to do that is
setColor and getColor do as their names imply?
Car myCar = new Car("Blue");
Car disCar = myCar;
Car stevesCar = new Car("Green");
disCar.setColor("Red");
myCar.setColor("Yellow");
System.out.print(disCar.getColor());