import testing.*; abstract class FamilyList { //To add the contents of names to this FamilyList abstract FamilyList append( FamilyList names ); } class EmptyFL extends FamilyList { EmptyFL() { } //new EmptyFL().append( new EmptyFL() ) -> new EmptyFL() //new EmptyFL().append( new LargerFL( "Fred", new EmptyFL() ) ) -> // new LargerFL( "Fred", new EmptyFL() ) //To add the contents of names to this EmptyFL FamilyList append( FamilyList names ) { // ... names ... return names ; } } class LargerFL extends FamilyList { String front; FamilyList rest; LargerFL( String front, FamilyList rest ) { this.front = front; this.rest = rest; } //new LargerFL( "Fred", new EmptyFL() ).append( new LargerFL( "Betty", new EmptyFL()) ) // --> new LargerFL( "Fred", new LargerFL( "Betty", new EmptyFL() )) //new LargerFL( "Bob", new LargerFL("JOhn", new EmptyFL())).append( new LargerFL("Lauren", new LargerFL("Monaca", new EmptyFL()))) // --> new LargerFL( "Bob", new LargerFL( "JOhn", new LargerFL( "Lauren", new LargerFL("Monaca", new EmptyFL())))) //new LargerFL( "Fred", new EmptyFL()).append(new EmptyFL() ) -> new LargerFL("Fred",new EmptyFL()) //To add the contents of names to this LargerFL FamilyList append( FamilyList names ) { // ... this.front ... this.rest.FamilyListMethod() ... names return new LargerFL( this.front, this.rest.append( names ) ); } } class FamilyListTests extends Test { FamilyListTests() { } FamilyList mt = new EmptyFL(); FamilyList one = new LargerFL("Sarah", this.mt); TestResult testAppendMT() { return this.compareObjects(this.mt.append(this.mt), this.mt); } TestResult testAppendMTNon() { return this.compareObjects(this.mt.append(this.one), this.one); } TestResult testAppendOne() { return this.compareObjects(this.one.append(this.mt), this.one); } TestResult testAppendOneOne() { return this.compareObjects(this.one.append(this.one), new LargerFL("Sarah",this.one)); } }