You're declaring result inside the scope of either the if statement or the else block. Once the code exits those blocks, your result variable is no longer in scope.
To fix it, simply declare your variable at the correct scope:
public String toString() {
String result;
if (isEmpty()) {
result = String.format("Interval: (EMPTY)");
} else {
result = String.format("Interval: [%s, %s]", Double.toString(left),
Double.toString(right));
}
return result;
}
Or just use the return statement in-line:
public String toString() {
if (isEmpty()) {
return String.format("Interval: (EMPTY)");
} else {
return String.format("Interval: [%s, %s]", Double.toString(left),
Double.toString(right));
}
}