Howdy. 

Web             Game 
--------------------------
Misato          Garrett 
Daniel R        Elise 
Jillian P       Noah
Patrick P       Nicholas
Tao             Jiang 
Rafael          Bihan 
Iris            Justin 
Yibo            Khalea
Keiland
Daniel C
Ryan 
Taylor 
Kefei 

I hope all submissions for Stage One are in, if not let me know. 

I will give you a book to read if you're interested in JSP and Servlets. 

I hope that today you can show me your projects or I help you finalize them.

C343 comes after C212 we're worried about the transition. 

We should start Homework 10. 

Homework 10 has three problems. 

In lab and later tonight I want to grade projects. 

The first problem in Homework 10 is the real problem. 

The other two are just corollaries. 

public class HomeworkTen {
  public static void main(String[] args) {
    LispList list = new NonEmptyList("A", 
                      new NonEmptyList("B", 
                        new NonEmptyList("C", 
                          new EmptyList())));
    System.out.println( list ); 
    
  }
}

public interface LispList {
  Object head(); // first 
  LispList tail(); // rest 
  boolean empty(); // empty? 
  // ... 
}

public class EmptyList implements LispList {
  public boolean empty() {
    return true;  
  }
  public LispList tail() {
    return null; // throw Exception 
  }
  public Object head() {
    return null;  // throw Exception 
  }
}

public class NonEmptyList implements LispList {
   private Object head;
   private LispList tail; 
   public NonEmptyList(Object head, LispList tail) {
     this.head = head; 
     this.tail = tail; 
   }
   public Object head() {
     return this.head; 
   }
   public LispList tail() {
     return this.tail; 
   }
   public boolean empty() {
     return false;  
   }
}

We clearly need a toString method. When we return...

There's more than one way to implement toString but here's one:

This class does not change:

public class HomeworkTen {
  public static void main(String[] args) {
    LispList list = new NonEmptyList("A", 
                      new NonEmptyList("B", 
                        new NonEmptyList("C", 
                          new EmptyList())));
    System.out.println( list );  
  }
}

Here's the EmptyList class: 

public class EmptyList implements LispList {
  public boolean empty() {
    return true;  
  }
  public LispList tail() {
    return null; // throw Exception 
  }
  public Object head() {
    return null;  // throw Exception 
  }
  public String toString() {
    return ""; 
  }
}

The toString in NonEmptyList is doing all the work:

public class NonEmptyList implements LispList {
   private Object head;
   private LispList tail; 
   public NonEmptyList(Object head, LispList tail) {
     this.head = head; 
     this.tail = tail; 
   }
   public Object head() {
     return this.head; 
   }
   public LispList tail() {
     return this.tail; 
   }
   public boolean empty() {
     return false;  
   }
   public String toString() {
     String answer = "[" + this.head();
     LispList a = this.tail(); 
     while (! a.empty()) {
       answer = answer + ", " + a.head(); 
       a = a.tail(); 
     }
     return answer + "]"; 
   }
}

The interface (our protocol) has not changed:

public interface LispList {
  Object head(); // first 
  LispList tail(); // rest 
  boolean empty(); // empty? 
  // ... 
}

Now what do we do next?

--