Grading assignments starting next week (with Lab Assignment Eight): 

Adrian German (dgerman): 

  Badger J, 
  Bogdanoff A, 
  Crutchfield W, 
  Feltner L, 
  Hebda J, 
  Langston J, 
  Mitts A, 
  Pedersen H, 
  Richards P, 
  Schumacher G, 
  Welsh M 

Yudou (Phoebe) He: 

  Barnes, 
  Branson, 
  Curtis, 
  Fu, 
  Holmes, 
  Man, 
  Niu, 
  Qian, 
  Robinson, 
  Shepherd

Seth (Xiaohui) Wang: 

  Bobe, 
  Corradin, 
  Dai, 
  Garcia, 
  Jackson, 
  Mantz III, 
  Ong, 
  Reddigari, 
  Root, 
  Song

Next let's consider the following:

Exercise 1 Develop a data and structure definition for storing a Frequency, 
           which combines a String and a Number, and representing that many 
           uses of the specified string.

public class Frequency {
  private String word; 
  private int count;   
  public void addOne() {
    this.count++; 
  } 
  public Frequency(String word, int number) {
    this.word = word; 
    this.count = number; 
  }
  public String getWord() {
    return this.word; 
  }
  public int getCount() {
    return this.count; 
  }
  public String toString() {
    return "(" + this.word + ", " + this.count + ")";
  }
  public static void main(String[] args) {
    Frequency a = new Frequency("mango", 3); 
    Frequency b = new Frequency("pear", 7); 
    System.out.println( a.toString() ); 
    System.out.println( b ); 
  } 
}

When I run this I get: 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Frequency
(mango, 3)
(pear, 7)
>

Exercise 2 Develop a data definition ListOfString which uses cons and empty 
           to hold arbitrarily many Strings. Similarly, develop a data definition 
           for ListOfFrequency.

public class ListOfString {
  private String       first;
  private ListOfString rest;    
  public String toString() {
    return this.first + " " + this.rest;  
  }
  public ListOfString(String first, ListOfString rest) {
    this.first = first; 
    this.rest = rest;
  } 
  public String getFirst() {
    return this.first; 
  }
  public ListOfString getRest() {
    return this.rest; 
  } 
  public static void main(String[] args) {
    ListOfString los1 = null; 
    ListOfString los2 = new ListOfString("narwal" , los1); 
    ListOfString los3 = new ListOfString("paper"  , los2); 
    ListOfString los4 = new ListOfString("word"   , los3); 
    ListOfString los5 = new ListOfString("laptop" , los4); 
    System.out.println( los1 ); 
    System.out.println( los2 ); 
    System.out.println( los3 ); 
    System.out.println( los4 ); 
    System.out.println( los5 ); 
  } 
}

Compile and run this to get: 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run ListOfString
null
narwal null
paper narwal null
word paper narwal null
laptop word paper narwal null


The other one is like this:

public class ListOfFrequency {
  private Frequency       first;
  private ListOfFrequency rest;    
  public String toString() {
    return this.first + " " + this.rest;  
  }
  public ListOfFrequency(Frequency first, ListOfFrequency rest) {
    this.first = first; 
    this.rest = rest;
  } 
  public Frequency getFirst() {
    return this.first; 
  }
  public ListOfFrequency getRest() {
    return this.rest; 
  } 
  public static void main(String[] args) {
    ListOfFrequency lof1 = null; 
    ListOfFrequency lof2 = new ListOfFrequency(new Frequency("narwal" , 2), lof1); 
    ListOfFrequency lof3 = new ListOfFrequency(new Frequency("paper"  , 5), lof2); 
    ListOfFrequency lof4 = new ListOfFrequency(new Frequency("word"   , 1), lof3); 
    ListOfFrequency lof5 = new ListOfFrequency(new Frequency("laptop" , 3), lof4); 
    System.out.println( lof1 ); 
    System.out.println( lof2 ); 
    System.out.println( lof3 ); 
    System.out.println( lof4 ); 
    System.out.println( lof5 ); 
  } 
}

Compile and run to obtain:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run ListOfFrequency
null
(narwal, 2) null
(paper, 5) (narwal, 2) null
(word, 1) (paper, 5) (narwal, 2) null
(laptop, 3) (word, 1) (paper, 5) (narwal, 2) null


Exercise 3 Design a function count-word which consumes a ListOfFrequency and a String 
           and adds 1 to the frequency for that string, producing a new ListOfFrequency. 
           If there is no Frequency for that string, the resulting ListOfFrequency 
           should have a Frequency with that string and the number 1.

public class LectureEight {
  public static ListOfFrequency countWord(ListOfFrequency lof, String word) {
    if (lof == null) {
      Frequency f = new Frequency(word, 1); 
      return new ListOfFrequency(f, lof); 
    } else {
      if (lof.getFirst().getWord().equals( word )) {
        lof.getFirst().addOne();
        return lof; 
      } else {
        return new ListOfFrequency( lof.getFirst() , 
                                     LectureEight.countWord( lof.getRest() ,
                                                             word  )
                                  ); 
      }
    }          
  }
  public static void main(String[] args) {
    ListOfFrequency lof1 = null; 
    System.out.println( lof1 ); 
    ListOfFrequency lof2 = LectureEight.countWord(lof1, "narwal");
    System.out.println( lof2 ); 
                    lof2 = LectureEight.countWord(lof2, "narwal");
    System.out.println( lof2 ); 
    ListOfFrequency lof3 = new ListOfFrequency(new Frequency("paper"  , 5), lof2); 
    System.out.println( lof3 ); 
    ListOfFrequency lof4 = new ListOfFrequency(new Frequency("word"   , 1), lof3); 
    System.out.println( lof4 ); 
    ListOfFrequency lof5 = new ListOfFrequency(new Frequency("laptop" , 3), lof4); 
    System.out.println( lof5 ); 
    ListOfFrequency lof6 = LectureEight.countWord(lof5, "word"); 
    System.out.println( lof6 ); 
    ListOfFrequency lof7 = LectureEight.countWord(lof6, "mouse"); 
    System.out.println( lof7 ); 
  } 
}

Exercise 4 Design a function count-all-words which takes a ListOfString and produces a 
           ListOfFrequency with the appropriate frequencies counted from the entire list 
           of strings.

Exercise 5 Download the text of Green Eggs and Ham into the same folder as your file 
           where you are completing this assignment. Then use the java.io.*; library 
           to create a list of words from the file. Then compute the frequencies of all 
           of the words in the file.

Exercise 6 Design a function which consumes a ListOfFrequency and produces a 
           ListOfFrequency that contains only the Frequencys from the original 
           list where the number is more than, say, 20. Use this to compute all 
           the words used more than 20 times in Green Eggs and Ham. Include this 
           list in your submission.

Attendance:

Jingzhe , Lauren , Paul     , Nick    , Trevor    , Jared 
Gabriela, Morgan , Jack     , Adam    , Jacquelyn , William
Jon Man , Daniel , Alex Ong , Brennan , Austin    , Logan 
Mark    , Yiming , Aleksa   , Walter  , James     , Mohan     
Judy    ,