// CS 2510, Assignment 3 import tester.*; // to represent a list of Strings interface ILoString { // combine all Strings in this list into one String combine(); } // to represent an empty list of Strings class MtLoString implements ILoString { MtLoString(){} // combine all Strings in this list into one public String combine() { return ""; } } // to represent a nonempty list of Strings class ConsLoString implements ILoString { String first; ILoString rest; ConsLoString(String first, ILoString rest){ this.first = first; this.rest = rest; } /* TEMPLATE FIELDS: ... this.first ... -- String ... this.rest ... -- ILoString METHODS ... this.combine() ... -- String METHODS FOR FIELDS ... this.first.concat(String) ... -- String ... this.first.compareTo(String) ... -- int ... this.rest.combine() ... -- String */ // combine all Strings in this list into one public String combine(){ return this.first.concat(this.rest.combine()); } } // to represent examples for lists of strings class ExamplesStrings{ ILoString mary = new ConsLoString("Mary ", new ConsLoString("had ", new ConsLoString("a ", new ConsLoString("little ", new ConsLoString("lamb.", new MtLoString()))))); // test the method combine for the lists of Strings boolean testCombine(Tester t){ return t.checkExpect(this.mary.combine(), "Mary had a little lamb."); } }