Add a method length to the LispList interface of Exercise P15.10 that returns the length of the list. Implement the method in the EmptyList and NonEmptyList classes.

Complete the following files:

EmptyList.java

NonEmptyList.java

Use the following files:

LispList.java

public interface LispList
{
   LispList NIL = new EmptyList();
   boolean isEmpty();
   Object head();
   LispList tail();
   LispList cons(Object obj);
   int length();
}

LispListTester.java

public class LispListTester
{
   public static void main(String[] args)
   {
      LispList list1 = new EmptyList();
      System.out.println(list1.length());
      System.out.println("Expected: 0");

      LispList list2 = new NonEmptyList("A", new EmptyList());
      System.out.println(list2.length());
      System.out.println("Expected: 1");

      LispList list3 = new NonEmptyList("A", new NonEmptyList("B",
         new NonEmptyList("C", new EmptyList())));
      System.out.println(list3.length());
      System.out.println("Expected: 3");

      LispList list4 = LispList.NIL.cons("E").cons("D").cons("C").cons("B").cons("A");
      System.out.println(list4.length());
      System.out.println("Expected: 5");
   }
}