This is the code that's relevant:
*
import java.util.function.Consumer;
/**
A Robot implemented with a dynamic array data structure
and providing "Sequence" capabilities. This is a homework assignment
inspired by Main: "Data Structures and Other Objects in Java" Chapter 3
(Sequence ADT). */
*
public class DynamicArrayPartSeq implements Robot, Cloneable { private static final int INITIAL_CAPACITY = 1;
// Data structure: Do not add or subtract from this: private String[] functions; private Part[] parts; private int size; private String function; private int currentIndex;
private static Consumer reporter = (s) -> System.out.println ("Invariant error: "+ s);
private boolean report(String error) { reporter.accept(error); return false; }
private boolean wellFormed() { // XXX: The invariant should be adjusted: no holes allowed // and it needs to check currentIndex and function
// 1. The "functions" and "parts" arrays must not be null.
// TODO
if (functions == null) {
return report("functions cant be null");
}
if (parts == null) {
return report("parts cant be null");
}
// 2. The "functions" and "parts" arrays are always the same length.
// TODO
if (functions.length != parts.length) {
return report ("functions and parts arrays should always bt the same length");
}
// 3. The size cannot be negative or greater than the length of the arrays.
// TODO
if (size < 0) {
return report ("size cant be negative");
}
if (size > functions.length) {
return report ("size can't be greater than functions length");
}
if (size > parts.length) {
return report ("size can't be greater than parts length");
}
// 4. None of the first “size” elements of either array can be null. (ie. no holes)
// TODO
if (size == 0) {
return report("first 'size' elements of either array cant be null");
}
// 5. The current index cannot be negative or greater than the size.
// TODO
if (currentIndex < 0) {
return report ("index cant be negative");
}
if (currentIndex > size) {
return report ("index cant be greater than the size");
}
// 6. If the function is not null and the current index is less than the size, then the
// function array must agree with the field at the current index.
// TODO
if (function != null && currentIndex < size) {
}
// If no problems discovered, return true
return true; }
I wrote out the first if regarding to check that the function isn't null and the current index is less than size. The second comment "function array must agree with the field at the current index" is throwing me off. I tried writing it as a second if statement inside the first, but I'm unsure on what to insert as the conditions.