Menu

public interface IndexedObject {public String toString();} class RomanIndexedObject implements IndexedObject { private int _i;

public interface IndexedObject {public String toString();}

class RomanIndexedObject implements IndexedObject {
private int _i;
private Object _o;
RomanIndexedObject(int i, Object o) { _i = i; _o = o; }
public String toString() {
return indexToString() + _o.toString();
}
private String indexToString() {
return Util.toRoman(_i);
}
}

class LetterIndexedObject implements IndexedObject {
private int _i;
private Object _o;
LetterIndexedObject(int i, Object o) { _i = i; _o = o; }
public String toString() {
return indexToString() + _o.toString();
}
private String indexToString() {
return Util.toLetter(_i);
}
}

As you can see, there is code duplication. Rewrite it to remove the duplication

Expert Answer

Step 1

To remove the code duplication in the RomanIndexedObject and LetterIndexedObject classes, you can cr…

OR