Consider the following interface:
a CBListADT is a cursor based list of cha
a newly created CBListADT is empty (contains no elements)
public interface CBListADT {
get the cu
ent element
public char get();
insert c before the cu
ent element
public void insert(char c);
remove the cu
ent element. return true if it was possible to do, false if not
public boolean remove();
move the cursor so that the first element is the cu
ent element
public void moveToFirst();
move the cursor to the next element, returning true if the move succeeded
and false if it is not possible to move to the next element
public boolean goNext();
}
Type your answers in the lines indicated by A1, A2, ... A7. Add lines if needed.
--------------------------------------------------------------------------------------
Q1.
Write a problem instance that describes the behavior of the remove()
method when the CBListADT has the following initial state:
a | b, c
A1:
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
Q2.
Write one sentence that explains your problem instance.
A2:
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
Q3.
Write a JUnit test method that implements your problem instance. Assume that a class
named CBListRaIMP exists that implements CBListADT. Assume all the methods
are implemented.
A3:
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
Q4.
Briefly explain each step in the JUnit method you wrote.
A4:
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
Q5.
Write a class named CBListRaIMP that implements the CBListADT interface using an a
ay
of char. Be sure to include any necessary data fields. NOTE: you only have to implement
the remove() method.
A5:
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
Q6.
Write a short paragraph explaining your CBListRaIMP implementation. Be sure to state the
ole of each data field and to explain each step in your method implementation.
A6:
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
Consider the method foo in the class Moo below.
public class Moo {
public static boolean foo(char[] a, int b, int c) {
XXXXXXXXXXif (b == a.length) {
XXXXXXXXXXreturn false;
}
XXXXXXXXXXif (c < 0 || b < c) {
XXXXXXXXXXreturn false;
}
XXXXXXXXXXfor (int i = b; i > c; i--) {
XXXXXXXXXXa[i] = a[i - 1];
}
a[c] = 'x';
XXXXXXXXXXreturn true;
}
}
Type your answers in the lines indicated by A1, A2 (add lines if needed).
--------------------------------------------------------------------------------------
Q1.
Explain how method foo works. Be sure to explain what its parameters are and how it
uses them. State what each line in the method does.
A1:
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
Q2.
State in ONE sentence what the purpose of method foo is. (Do NOT explain the steps
method foo performs. That is the first question.)
A2:
--------------------------------------------------------------------------------------