<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:gd="http://schemas.google.com/g/2005" gd:etag="W/&quot;A0cFQHs7fCp7ImA9WxFUFE0.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431</id><updated>2010-06-24T15:50:11.504-04:00</updated><title>CSCE 145</title><subtitle type="html">Algorithmic Design I: Sections 5 and 6</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://www.csce145.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://www.csce145.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>78</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/csce145" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="csce145" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;CkEHRX0_cSp7ImA9WxFTGE8.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-6831901421554499855</id><published>2010-04-09T09:32:00.001-04:00</published><updated>2010-04-09T09:43:54.349-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-04-09T09:43:54.349-04:00</app:edited><title>Rate This Professor</title><content type="html">&lt;p&gt;I thought I would put up this post so students that took this class last Fall could add their comments for the benefit of those who will be taking it this Fall and for my own benefit. The reviews I got for the last class included the usual complaints:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;b&gt;"Tests were graded very harsh"&lt;/b&gt; Yes, you can see for yourself the &lt;a href="http://www.csce145.com/2009/12/final-averages.html"&gt;point values&lt;/a&gt; for the final test. But points are not grades, the final letter grade for the class is based on a curve.&lt;/li&gt;

&lt;li&gt;&lt;b&gt;"challenging"&lt;/b&gt;. Yes. More specifically, learning to program takes a &lt;em&gt;lot&lt;/em&gt; of time. Be prepared to put in many hours in front of the computer.&lt;/li&gt;

&lt;li&gt;&lt;b&gt;"this should not be a requirement for Math/EE/x majors"&lt;/b&gt;. That's out of my control. Still, ability to program comes in handy when you want to &lt;a href="http://careers.cse.sc.edu"&gt;find a job&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
The &lt;b&gt;goal of this class&lt;/b&gt; is for every student to leave with basic programming skills. For example, look at &lt;a href="http://www.csce145.com/2009/12/final-test.html"&gt;question 1 in our final test&lt;/a&gt;. Every student who passes 145 should be able to write that program. To do so the student needs to know about variables, string manipulation, loops, and how to put all these together to get it done. These are just some of the basic skills students learn. You can take a look at the textbook to see all the topics we cover.
&lt;/p&gt;
&lt;p&gt;
So, if you have taken this class and have some suggestions for me or future students on how to achieve this goal, please leave a comment.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-6831901421554499855?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/6831901421554499855/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2010/04/rate-this-professor.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/6831901421554499855?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/6831901421554499855?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2010/04/rate-this-professor.html" title="Rate This Professor" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;AkIFR344cSp7ImA9WxBTF0w.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-7828667585820024026</id><published>2009-12-13T10:33:00.001-05:00</published><updated>2009-12-13T10:35:16.039-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-13T10:35:16.039-05:00</app:edited><title>Final Averages</title><content type="html">Below is the grade distribution for the final test. Some students did not show up for the final, thus the 0 grades.&lt;p&gt;
&lt;center&gt;
&lt;img src="https://spreadsheets.google.com/oimg?key=0Ao2vkgerarbjdDV1eXo3WGJ6bmMwa2E5TFBhX0E1OWc&amp;oid=16&amp;v=1260718282966" /&gt;
&lt;/center&gt;

The final grade distribution for the whole class is:&lt;p&gt;
&lt;center&gt;
&lt;img src="https://spreadsheets.google.com/oimg?key=0Ao2vkgerarbjdDV1eXo3WGJ6bmMwa2E5TFBhX0E1OWc&amp;oid=17&amp;v=1260718395355" /&gt;
&lt;/center&gt;

You will be receiving you final grade shortly.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-7828667585820024026?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/7828667585820024026/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/12/final-averages.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/7828667585820024026?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/7828667585820024026?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/12/final-averages.html" title="Final Averages" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CUYEQHs8fyp7ImA9WxBTFk8.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-5278612632824543835</id><published>2009-12-11T17:05:00.026-05:00</published><updated>2009-12-12T08:05:01.577-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-12T08:05:01.577-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="solution" /><title>Final Test</title><content type="html">&lt;h1&gt;
145 Final Test&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;&lt;b&gt;(10%)&lt;/b&gt; Implement a method which takes as input two
      Strings and returns one String which is formed by interleaving
      the two arguments. Assume that the two input strings have the
      same length. For example, if given the input
&lt;br /&gt;
&lt;pre&gt;"abcde"
"12345"
&lt;/pre&gt;
then it should return a String with the value:
&lt;br /&gt;
&lt;pre&gt;"a1b2c3d4e5"
&lt;/pre&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;  /**
   * Interleaves the letters of first and second. Assumes that first and second have the same length.
   * @return the interleaved string
   */
  public static String interleave(String first, String second){
    String result = "";
    for (int i =0; i &amp;lt; first.length(); i++){
      result += first.substring(i, i+1) + second.substring(i,i+1);
    }
    return result;
  }
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;(10%)&lt;/b&gt; Implement a method that takes an array of
      &lt;code&gt;long&lt;/code&gt; values representing phone numbers and prints
      out how many of those phone numbers are in Columbia (803),
      Greenville (864), and Charleston (843). You &lt;b&gt;must use a switch
      statement&lt;/b&gt; in your method.&lt;br /&gt;For example, if we call your
      method with the following array &lt;code&gt;n&lt;/code&gt; as input:
&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;long[] n = {8031234567l, 8649878787l, 8031223456l, 8034543212l, 8642323214l, 8432341231l};
&lt;/pre&gt;
you will print out:
&lt;br /&gt;
&lt;pre&gt;Columbia:3
Greenville:2
Charleston:1
&lt;/pre&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;  public static void countAreaCodes (long[] phoneNumber){
    int columbia = 0;
    int greenville = 0;
    int charleston = 0;
    for (int i =0; i &amp;lt; phoneNumber.length;i++){
      int areaCode = (int) (phoneNumber[i] / 10000000);
      switch (areaCode) {
      case 803: 
        columbia++;
        break; //Don't forget the breaks!
      case 864:
        greenville++;
        break;
      case 843:
        charleston++;
      }
    }
    System.out.println("Columbia:" + columbia);
    System.out.println("Greenville:" + greenville);
    System.out.println("Charleston:" + charleston);
  }
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;(10%)&lt;/b&gt; What does the following program print out?

    &lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public class Enigma {
  
  private static int x;
  
  protected String s; 
  
  public Enigma(int x, String s){
    System.out.println("Creating an Engima");
    this.x = x;
    this.s = s;
  }
  
  public void addItUp(int z){
    x = x + z;
  }
  
  public void merge(Enigma e){
    s = s + "+" +  e.s;
  }
  
  public String toString(){
    return "s=" + s + " x=" + Integer.toString(x);
  }

}

public class Mystery extends Enigma {
  
  private int y;
  
  public Mystery (int x, int y, String s){
    super(x,s);
    System.out.println("Creating a Mystery");
    this.y = y;
  }
  
  public void addItUp(int z){
    y = y + z;
  }
  
  public String toString(){
    return super.toString() + " y=" + Integer.toString(y);
    
  }
  
}

public class Paradox extends Mystery {

  public Paradox(int x, int y, String s) {
    super(x, y, s);
    System.out.println("Creating a Paradox");
  }
  
  public void merge (Paradox p){
    s = "Do not cross the paradoxes!";
  }
}

public class Main {

  public static void main(String[] args) {
    Paradox p = new Paradox (5,10,"This sentence is false");
    Enigma e = new Enigma(33, "Black hole");
    System.out.println(p);
    System.out.println(e);
    e.merge(p);
    System.out.println(e);
    p.merge(p);
    System.out.println(p);
    e.merge(p);
    System.out.println(e);
    p.addItUp(100);
    System.out.println(p);
    Enigma e2 = (Enigma)p;
    e2.addItUp(500);
    System.out.println(e2);
  }
}
&lt;/pre&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
&lt;br /&gt;
&lt;pre&gt;Creating an Engima
Creating a Mystery
Creating a Paradox
Creating an Engima
s=This sentence is false x=33 y=10
s=Black hole x=33
s=Black hole+This sentence is false x=33
s=Do not cross the paradoxes! x=33 y=10
s=Black hole+This sentence is false+Do not cross the paradoxes! x=33
s=Do not cross the paradoxes! x=33 y=110
s=Do not cross the paradoxes! x=33 y=610
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;(10%)&lt;/b&gt; A diagonal matrix is a 2-dimensional square
      array of integers where the numbers on the diagonal are all 1
      and the rest are 0. For example, the following is a 1x1 diagonal
      matrix:
&lt;br /&gt;
&lt;pre&gt;1
&lt;/pre&gt;
and this is a 4x4 diagonal matrix:
&lt;br /&gt;
&lt;pre&gt;1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
&lt;/pre&gt;
Implement a method that takes an integer &lt;i&gt;n&lt;/i&gt; and
returns an &lt;i&gt;n x n&lt;/i&gt; array of integers that is a diagonal matrix.


&lt;br /&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
    &lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;  public static int[][] makeDiagonalMatrix (int size){
    int [][] result = new int[size][size];
    for (int i = 0; i&amp;lt;size; i++ ){
      result[i][i] = 1;
    }
    return result;
  }
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;

      &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;(10%)&lt;/b&gt; Implement a class called &lt;code&gt;Tracker&lt;/code&gt;
      which keeps track (in variables) of
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;how many times each instance's &lt;code&gt;toString()&lt;code&gt; method has been called&lt;/code&gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;the total number of times all instances of the class have had their &lt;code&gt;toString()&lt;/code&gt; invoked.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
    &lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public class Tracker {
  
  private static int totalCount = 0;
  
  private int count;
  
  public Tracker(){
    count = 0;
  }
  
  public String toString() {
    count++;
    totalCount++;
    
    return "";
  }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;(10%)&lt;/b&gt; Implement an &lt;code&gt;Exception&lt;/code&gt; called
      &lt;code&gt;SilentException&lt;/code&gt; such that a we &lt;b&gt;do not&lt;/b&gt; have
      to place within a &lt;code&gt;try.catch&lt;/code&gt; block a method that
      throws &lt;code&gt;SilentException&lt;/code&gt;.
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
    &lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public class SilentException extends RuntimeException {
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;(10%)&lt;/b&gt; Implement a method that calculates the shipping
      and handling costs of an &lt;code&gt;Order&lt;/code&gt;, which has methods
      (these exists, you don't have to write them):
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;boolean oversized()&lt;/code&gt;: returns true if this order is for an oversized item.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;CARRIER getCarrier()&lt;/code&gt;: where CARRIER is defined as &lt;code&gt;enum CARRIER {UPS, FEDEX, USPS}&lt;/code&gt;, returns the carrier. (A carrier is a company that ships packages. UPS, FEDEX, and USPS are the names of three different carrier companies.)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;boolean rush()&lt;/code&gt;: return true if this a rush order.&lt;/li&gt;
&lt;/ol&gt;
The method you will implement is called &lt;code&gt;double
getShippingCosts(Order o)&lt;/code&gt; and it will calculate the the
shipping and handling costs. The shipping costs for the different
carries are given in this table: &lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;table border="1"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;th&gt;&lt;br /&gt;
&lt;/th&gt;&lt;th&gt;UPS&lt;br /&gt;
&lt;/th&gt;&lt;th&gt;FEDEX&lt;br /&gt;
&lt;/th&gt;&lt;th&gt;USPS&lt;br /&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Regular&lt;br /&gt;
&lt;/td&gt;&lt;td&gt;$10&lt;br /&gt;
&lt;/td&gt;&lt;td&gt;$12&lt;br /&gt;
&lt;/td&gt;&lt;td&gt;$9&lt;br /&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Oversized&lt;br /&gt;
&lt;/td&gt;&lt;td&gt;$15&lt;br /&gt;
&lt;/td&gt;&lt;td&gt;$22&lt;br /&gt;
&lt;/td&gt;&lt;td&gt;$9&lt;br /&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;&lt;br /&gt;

The is also a standard handling fee of $4 for all packages. Also, if
it is a rush order then you must add an extra 10% to the regular
shipping costs.

&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
    &lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;  public static double getShippingCosts(Order o){
    double basePrice = 0;
    switch (o.getCarrier()) {
    case UPS:
      if (o.oversized())
        basePrice = 15;
      else 
        basePrice = 10;
      break;
    case FEDEX:
      if (o.oversized())
        basePrice = 22;
      else
        basePrice = 11;
      break;
    case USPS:
      basePrice = 9;
    }
    if (o.rush())
      basePrice = basePrice * 1.10;
    basePrice += 4;
    return basePrice;
  }
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;(15%)&lt;/b&gt; Implement a method that takes a
      &lt;code&gt;String&lt;/code&gt; input which represents a DNA sequence and
      returns the index of the start of longest string of 'A' letters
      in the sequence. If there are no A's then return -1. For example, &lt;br /&gt;
&lt;br /&gt;
given input "ACTAAAGA" you return 3,&lt;br /&gt;
given input "AAAAGA" you return 0,&lt;br /&gt;
given input "CTGATTAAAA" you return 6,&lt;br /&gt;
given input "CTG" you return -1&lt;br /&gt;
&lt;br /&gt;

&lt;br /&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;  /**
   * This solution is good enough for 145*/
  public static int longestRepeatA(String dna){

    int longestIndex = -1;
    int longestCount = 0;
    for (int i =0; i &amp;lt; dna.length(); i++){
      int lengthA = 0;
      while (i + lengthA &amp;lt; dna.length() &amp;amp;&amp;amp; dna.charAt(i+lengthA) == 'A'){
        lengthA++;
      };
      if (lengthA &amp;gt; longestCount){
        longestCount = lengthA;
        longestIndex = i;
      }
    }
    return longestIndex;
  }

  /** More experienced developers realize that the above is O(N^2) and that 
   * there is a way to implement it in linear time, like this: */ 
  public static int longestRepeatB(String dna){
    int longestIndex = -1;
    int longestCount = 0;
    int count = 0;
    for (int i = 0; i &amp;lt; dna.length(); i++){
      if (dna.charAt(i) == 'A') {
        count++;
      }
      if (count &amp;gt; longestCount) {
        longestCount = count;
        longestIndex = i - count + 1;
      }
      if (dna.charAt(i) != 'A'){
        count = 0;
      }
    }
    return longestIndex;
  }
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;(15%)&lt;/b&gt; Implement a method that calculates the average
      of an array of grades after first dropping the &lt;b&gt;lowest 4
      grades&lt;/b&gt;. That is, implement:
&lt;br /&gt;
&lt;pre&gt;double getAverageDropFourLowest(double [] grade)
&lt;/pre&gt;
Assume that &lt;code&gt;grades.length &amp;gt;= 5&lt;/code&gt;. For example, when given 
&lt;br /&gt;
&lt;pre&gt;double[] grade = {100,0,0,0,5,80,90};
&lt;/pre&gt;
as input, your method should return
&lt;br /&gt;
&lt;pre&gt;90.0&lt;/pre&gt;
&lt;b&gt;Alert:&lt;/b&gt; Notice that this has to work when the lowest grades match,
like in the example above where 3 of them where 0.&lt;br /&gt;&lt;br /&gt;

&lt;br /&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
    &lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;  /** Returns an an array identical to grades but without the lowest number in grades dropped.
   * if there are more than one minimum we only drop the first one.
   * @param gradesthe array of grades
   * @return a new array of size 1 less than grades.
   */
  public static double[] dropMin(double [] grade){
    double minval = grade[0];
    double[] result = new double[grade.length - 1];
    for (double i : grade){
      if (i &amp;lt; minval)
        minval = i;
    }
    int j = 0; //index into result
    for (int i = 0; i &amp;lt; grade.length; i++){
      if (j &amp;lt; i){ //already dropped min, so just copy the rest of the array
        result[j++] = grade[i];
      }
      else if (grade[i] &amp;gt; minval) { //not the min
        result[j++] = grade[i];
      }
      //if j==i and grades[i] == minval we do nothing, so i increases while j stays the same, 
      // thus ignoring this grade[i]        
    }
    return result;
  }
  
  /** Returns the average after dropping the lowest 2 grades. */  
  public static double getAverageDropFourLowest(double [] grades){
    double[] g = FinalTest.dropMin(grades);
    g = FinalTest.dropMin(g);
    g = FinalTest.dropMin(g);
    g = FinalTest.dropMin(g);
    
    double sum = 0;
    for (double i : g){
      sum += i;
    }
    return sum / (double) g.length;
    
  }
  
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-5278612632824543835?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/5278612632824543835/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/12/final-test.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/5278612632824543835?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/5278612632824543835?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/12/final-test.html" title="Final Test" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;D0UNQns5eCp7ImA9WxBTFEo.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-7098323873783874137</id><published>2009-12-04T18:00:00.004-05:00</published><updated>2009-12-10T15:01:33.520-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-10T15:01:33.520-05:00</app:edited><title>Screencasts: kinda useful</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
The result of my little &lt;a href="http://www.csce145.com/2009/12/were-screencasts-useful-to-you.html"&gt;screencast survey&lt;/a&gt; thus far is:&lt;br /&gt;
&lt;br /&gt;
&lt;div style="text-align: center;"&gt;
&lt;b&gt;Were the screencasts useful to you?&lt;/b&gt; &lt;br /&gt;
&lt;/div&gt;
&lt;center&gt;
&lt;img src="http://spreadsheets.google.com/oimg?key=0Ao2vkgerarbjdFMtVjlpNHIwbk55VDhsazBGdHZ0QWc&amp;oid=2&amp;v=1260475084646" /&gt;
&lt;/center&gt;
&lt;br /&gt;
So, slightly more useful than not. Most of the people who did not find them usefull did not leave comments. But, one did express a preference for textbook. I too prefer to learn new programming languages by sitting back with a book, so I definitely sympathisze.&lt;br /&gt;
&lt;br /&gt;
Someone else pointed out that he could not ask me a question when he got to a part he did not understand and would forget by the time class came around. In class I suggested students should send me a quick email (or IM) when they came across some part of the video that confused them and I would answer these in class, but I only received a couple of emails during the semester.&lt;br /&gt;
&lt;br /&gt;
Someone who liked them felt it is good to actually see things getting done. This is why I like watching screencasts of, say, using the Google App Engine, and I thought more students would mention it. But only one did.&lt;br /&gt;
&lt;br /&gt;
In any case, the &lt;a href="http://www.csce145.com/2009/12/were-screencasts-useful-to-you.html"&gt;survey is still open&lt;/a&gt; so fill it out if you haven't! The graph above will automatically update to show your vote. Isn't software wonderful!&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-7098323873783874137?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/7098323873783874137/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/12/screencasts-kinda-useful.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/7098323873783874137?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/7098323873783874137?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/12/screencasts-kinda-useful.html" title="Screencasts: kinda useful" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEIFQHczcCp7ImA9WxNaGEg.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-6962931954440958488</id><published>2009-12-03T09:31:00.002-05:00</published><updated>2009-12-03T11:08:31.988-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-03T11:08:31.988-05:00</app:edited><title>Grade Distributions</title><content type="html">The grade distribution for Test 3 is:

&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/_mMuRlDPULDs/SxfK-Igo6uI/AAAAAAAACY8/8oZsrIqVB7s/s1600/grade_distribution_for_test_3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="192" src="http://2.bp.blogspot.com/_mMuRlDPULDs/SxfK-Igo6uI/AAAAAAAACY8/8oZsrIqVB7s/s320/grade_distribution_for_test_3.png" width="320" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
The grade distribution of the weighted average of all grades so far (that is, the grade you would get if there was no final) is:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/_mMuRlDPULDs/SxfiegxoB2I/AAAAAAAACZM/FFNE8mPjo9M/s1600-h/average_pre-final_test.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_mMuRlDPULDs/SxfiegxoB2I/AAAAAAAACZM/FFNE8mPjo9M/s320/average_pre-final_test.png" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
And, one final correlation graph:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/_mMuRlDPULDs/SxfQVwhUHzI/AAAAAAAACZE/w_gs3-cepKs/s1600-h/image.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/_mMuRlDPULDs/SxfQVwhUHzI/AAAAAAAACZE/w_gs3-cepKs/s320/image.png" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-6962931954440958488?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/6962931954440958488/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/12/grade-distributions.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/6962931954440958488?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/6962931954440958488?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/12/grade-distributions.html" title="Grade Distributions" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_mMuRlDPULDs/SxfK-Igo6uI/AAAAAAAACY8/8oZsrIqVB7s/s72-c/grade_distribution_for_test_3.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DUUAR348cCp7ImA9WxNaF0s.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-4708718906386298875</id><published>2009-12-02T10:13:00.004-05:00</published><updated>2009-12-02T10:20:46.078-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-02T10:20:46.078-05:00</app:edited><title>Were the Screencasts useful to You?</title><content type="html">This semester, for the first time, I did screencasts (videos) for each chapter in the textbook. Could you please fill out the survey below so I can gauge how useful they were to students. Thanks! (Remember to click on the submit button when you are done.)&lt;br/&gt;&lt;br/&gt;

&lt;iframe src="http://spreadsheets.google.com/embeddedform?key=0Ao2vkgerarbjdFMtVjlpNHIwbk55VDhsazBGdHZ0QWc" width="760" height="572" frameborder="0" marginheight="0" marginwidth="0"&gt;Loading...&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-4708718906386298875?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/4708718906386298875/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/12/were-screencasts-useful-to-you.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/4708718906386298875?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/4708718906386298875?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/12/were-screencasts-useful-to-you.html" title="Were the Screencasts useful to You?" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEMFRno_fip7ImA9WxNaF0s.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-1002027224519954349</id><published>2009-12-02T10:06:00.000-05:00</published><updated>2009-12-02T10:06:57.446-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-02T10:06:57.446-05:00</app:edited><title>Final Exam Practice Questions</title><content type="html">As mentioned in class, the final is on Friday December 11 @ 2:00pm (to 5:00pm) in our classroom. It will be just like all the other tests: open book, no computers. The test will focus a bit more on the first chapters as these deal with the basic of all programming languages: variables, loops, methods, arrays, etc.

Below are links to some practice questions. I also recommend you do all the programming exercises from the textbook. Like I said the first day, the only way to learn to program is by programming, a lot. Have fun with these!

&lt;ol&gt;

&lt;li&gt;Write a method that &lt;a href="http://programmingquestions.blogspot.com/search/label/easy#6591467002351931106"&gt;finds a given number in a sorted array&lt;/a&gt;.&lt;/li&gt;

&lt;li&gt;Write a method that returns an array with &lt;a href="http://programmingquestions.blogspot.com/search/label/easy#431347144965738594"&gt;the first &lt;em&gt;n&lt;/em&gt; Fibonnaci numbers&lt;/a&gt;. &lt;/li&gt;


&lt;li&gt;Write a method that takes as input a 3x3 array of integers and &lt;a href="http://programmingquestions.blogspot.com/search/label/easy#8360552781321580397"&gt;returns true if that array is a magic square&lt;/a&gt;.&lt;/li&gt;

&lt;li&gt;Implement a simple &lt;a href="http://programmingquestions.blogspot.com/search/label/easy#1786844450056818823"&gt;1-dimensional automata&lt;/a&gt;.

&lt;li&gt;Once your 1D automata works, try working an a simple &lt;a href="http://programmingquestions.blogspot.com/search/label/easy#1897447426409100789"&gt;2D automata&lt;/a&gt;.&lt;/li&gt;


&lt;li&gt;Write a method that &lt;a href="http://programmingquestions.blogspot.com/search/label/easy#1215685822466720019"&gt;prints out a simple distribution graph&lt;/a&gt;.&lt;/li&gt;


&lt;li&gt;Implement a class that &lt;a href="http://programmingquestions.blogspot.com/search/label/easy#6658172179881315185"&gt;limits the number of instances of itself to 4&lt;/a&gt;.&lt;/li&gt;

&lt;li&gt;Write a method that &lt;a href="http://programmingquestions.blogspot.com/search/label/easy#3182643010159269487"&gt;reverses an array in place.&lt;/a&gt;&lt;/li&gt;


&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-1002027224519954349?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/1002027224519954349/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/12/final-exam-practice-questions.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/1002027224519954349?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/1002027224519954349?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/12/final-exam-practice-questions.html" title="Final Exam Practice Questions" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;C0cARXo7cCp7ImA9WxNaF00.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-1702854836960006349</id><published>2009-12-01T15:36:00.003-05:00</published><updated>2009-12-01T15:57:24.408-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-01T15:57:24.408-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="lab test" /><title>Lab test 3 for Section 006</title><content type="html">Write a program to implement a simple selling machine.
&lt;br&gt;&lt;/br&gt;
Each instance of the selling machine can hold 10 items using ArrayList. Partial program is given and you need to finish all the methods. You can add new items to the selling machine and get items from it if there is one. You need to implement a method to save the selling record (date &amp; item name) to a file. You can use the Exception class for exception handling.
&lt;br&gt;&lt;/br&gt;
In this lab test, we only consider one type of the items, the Drink class. Code is given.
&lt;br&gt;&lt;/br&gt;
Please check your email box for the codes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-1702854836960006349?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/1702854836960006349/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/12/lab-test-3-for-section-006.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/1702854836960006349?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/1702854836960006349?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/12/lab-test-3-for-section-006.html" title="Lab test 3 for Section 006" /><author><name>Xu Sun</name><uri>http://www.blogger.com/profile/13502695489105587650</uri><email>xusun09@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14239689565294866887" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEcDSHszfyp7ImA9WxNaF00.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-5347175998238482632</id><published>2009-12-01T14:00:00.004-05:00</published><updated>2009-12-01T16:14:39.587-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-01T16:14:39.587-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="solution" /><title>Test 3</title><content type="html">&lt;h1&gt;
145 Test 3: Fall 2009&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;&lt;b&gt;(20%)&lt;/b&gt; What does the following program print out?
    &lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public class MyExceptions {

  public int trySomething(int x) throws Exception{

    if (x &amp;lt; 0) {
      throw new Exception("X is less than 0");
    }
    return 5;

  }


  public static void main(String[] args){
    MyExceptions m = new MyExceptions();
    try {
      System.out.println("Starting");
      int result = m.trySomething(10);
      System.out.println("Got " + result);
      result = m.trySomething(- 10);
      System.out.println("Got " + result);
      System.out.println("No more tries");
    }
    catch (Exception e){
      System.out.println(e.getMessage());
    }
    System.out.println("Done");
  }

}
&lt;/pre&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
&lt;br /&gt;
&lt;pre&gt;Starting
Got 5
X is less than 0
Done
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;(10%)&lt;/b&gt; In the program above, what would happen with we
      removed the whole &lt;code&gt;catch&lt;/code&gt; block? Would the program
      compile or not? If you think it would not compile then explain
      what the compiler complains about. If you think is would compile
      then show what the program would print out when run.

&lt;br /&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt; It does not compile. You cannot have a &lt;code&gt;try&lt;/code&gt; without a &lt;code&gt;catch&lt;/code&gt;.
&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;(10%)&lt;/b&gt; Implement a class called &lt;code&gt;Employee&lt;/code&gt;,
      with data members &lt;code&gt;String name&lt;/code&gt; and &lt;code&gt;int
      salary&lt;/code&gt;. Make sure that instances of your
      &lt;code&gt;Employee&lt;/code&gt; can be written out to a binary file. But,
      &lt;b&gt;do not&lt;/b&gt; write the code to write instances to a file, just
      make sure that instances of &lt;code&gt;Employee&lt;/code&gt; can be written
      out to a binary file.

&lt;br /&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
    &lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public class Employee implements Serializable {

  private String name;
  private int salary;

  /** Add other methods, as needed. */

}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;(20%)&lt;/b&gt; Given the following text file, called &lt;i&gt;data.txt&lt;/i&gt;:
&lt;br /&gt;
&lt;pre&gt;123432
3.14151
Ringo
&lt;/pre&gt;
write a program that reads those three values from the text file into an integer, double, and string variables, respectively.
&lt;br /&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
    &lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

public class ReadFile {

  public static void main (String[] args){

    String fileName = "data.txt";

    try {
      Scanner inputStream = new Scanner(new File(fileName));
      int i = inputStream.nextInt();
      inputStream.nextLine();
      double d = inputStream.nextDouble();
      inputStream.nextLine();
      String s = inputStream.next();
      System.out.println("i=" + i + "\nd=" + d + "\ns=" + s);
    }
    catch (FileNotFoundException e){
      System.out.println("File Not Found");
    }
  }

}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;(20%)&lt;/b&gt; A fast way of finding the greatest common divisor (&lt;code&gt;gcd&lt;/code&gt;) of two numbers &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; is by using the following recursive definition of &lt;code&gt;gcd(x,y)&lt;/code&gt;:
&lt;br /&gt;
&lt;pre&gt;the gcd(x,y) is equal to the gcd of y and x%y,
the gcd(x,0) is equal to x.
&lt;/pre&gt;
Implement a recursive function that calculates the greatest common division of any two integers.
&lt;br /&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
    &lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public class GCD {

  /** Calculate the greatest common division, using the recursive function:
      gcd(x,y) = gcd(y,x%y)
      gcd(x,0) = x  */
  public static int gcd (int x, int y){
        if (y == 0)
          return x;
        return GCD.gcd(y, x%y);
  }

  public static void main (String[] args){
    System.out.println(GCD.gcd(10,5));
    System.out.println(GCD.gcd(10,1));
    System.out.println(GCD.gcd(8,6));
    System.out.println(GCD.gcd(121,11));
  }


}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;(20%)&lt;/b&gt; The following program contains two compile-time errors. What are they?
    &lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;import java.util.ArrayList;

public class Test&amp;lt;Type, E&amp;gt;{

  private ArrayList&amp;lt;Type&amp;gt; list;

  private ArrayList&amp;lt;E&amp;gt; another;

  public Test(){
    list = new ArrayList&amp;lt;E&amp;gt;();
    another = new ArrayList&amp;lt;E&amp;gt;();
  }

  public Type badFunction(E x, Type t){
    E y = x;
    Type tt = t;
    list.add(t);
    another.add("Alice");
    Test&amp;lt;String,String&amp;gt; justMe = new Test&amp;lt;String,String&amp;gt;();
    justMe.add("Bob", "Charlie");
    return tt;
  }

}
&lt;/pre&gt;
&lt;div class="solution"&gt;
&lt;b&gt;Answer:&lt;/b&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;The line  &lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;list = new ArrayList&amp;lt;E&amp;gt;();&lt;/pre&gt;
is wrong because the type &lt;code&gt;E&lt;/code&gt; should be &lt;code&gt;Type&lt;/code&gt; as per the declaration of &lt;code&gt;list&lt;/code&gt;.

&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;The line &lt;br /&gt;
&lt;pre&gt;another.add("Alice");&lt;/pre&gt;
because we cannot assume that the type of &lt;code&gt;another&lt;/code&gt; will be &lt;code&gt;ArrayList&amp;lt;String&amp;gt;&lt;/code&gt;.
&lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-5347175998238482632?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/5347175998238482632/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/12/test-3.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/5347175998238482632?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/5347175998238482632?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/12/test-3.html" title="Test 3" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>2</thr:total></entry><entry gd:etag="W/&quot;DkcEQX04eyp7ImA9WxNaFkQ.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-7101825820301674982</id><published>2009-12-01T14:00:00.003-05:00</published><updated>2009-12-01T14:00:00.333-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-01T14:00:00.333-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="lab test" /><title>SECTION 005: Lab test 03</title><content type="html">&lt;p&gt;The Towers of Hanoi is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.&lt;/p&gt;

&lt;p&gt;The objective of the puzzle is to move the entire stack to another rod, obeying the following rules: &lt;/p&gt;

&lt;p&gt;1. Only one disk may be moved at a time. &lt;/p&gt;
&lt;p&gt;2. Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod. &lt;/p&gt;
&lt;p&gt;3. No disk may be placed on top of a smaller disk. &lt;/p&gt;

&lt;p&gt;Below you will find a partial implementation of a Tower of Hanoi with two methods missing: getHeight and hanoi. For this test you will implement these methods. &lt;/p&gt;
&lt;p&gt;--- the start Pole, destination Pole and the intermediate Pole are labeled A, B, C.&lt;/p&gt;
&lt;p&gt;--- Each disk is labeled (from 1 to the n, n is the height of the tower)&lt;/p&gt;
&lt;p&gt;--- Disk 1 is the smallest disk, and Disk n is the largest one.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_TX8m2mjYJTA/SxViOCkJj7I/AAAAAAAAFjg/zWc2srewdSg/s1600/hanoi4.gif"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 400px; height: 324px;" src="http://1.bp.blogspot.com/_TX8m2mjYJTA/SxViOCkJj7I/AAAAAAAAFjg/zWc2srewdSg/s400/hanoi4.gif" alt="" id="BLOGGER_PHOTO_ID_5410338520701702066" border="0" /&gt;&lt;/a&gt;

&lt;p&gt; &lt;strong&gt;Hint &lt;/strong&gt;: The idea is that the method of moving n disks from start pole to destination pole is the same as the method of moving n-1 disks. For example, initially the tower has height 5, we must&lt;span style="font-weight: bold;"&gt; recursively&lt;/span&gt; move a tower of height 4 from A to C, move the biggest disk 5 from A to B (by simply calling method moveDisk), and finally &lt;span style="font-weight: bold;"&gt;recursively&lt;/span&gt; move the tower of height 4 to B from C.  &lt;/p&gt;



&lt;pre class="prettyprint lang-java"&gt;
public class HanoiTower {
 
static int moves = 0;  //number of moves so far

/*Method getHeight is used to get the height of tower from user input*/
static int getHeight()
{
   // TO DO
      
}

/*Method hanoi moves the tower of height n recursively
 * it accept four arguments: the height of the current tower n, the fromPole, the toPole and the withPole.
 * @param n the height of the current tower
 * @param fromPole the start pole
 * @param toPole the destination pole
 * @param withPole the intermediate pole
 * */
static void hanoi(int n, char  fromPole, char  toPole, char  withPole)
{
   // TO DO
}

/*Method moveDisk move the disk of diskLabel by simply printing on the console each move*/
static void moveDisk(int diskLabel, char fromPole, char toPole)
{
     moves++;
     System.out.println("steps: "+ moves);
     System.out.println("Move " + diskLabel + " from " + fromPole + " to " +toPole);
}

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub

    int TowerHeight;
    char FromPole='A', ToPole='B', WithPole='C';

    System.out.println("Please Enter Tower height...");

    TowerHeight = getHeight();

    hanoi(TowerHeight, FromPole, ToPole, WithPole);


}

}

&lt;/pre&gt;

&lt;p&gt;Here is the output of height of 3 after you properly implement the methods:&lt;/p&gt;

&lt;p&gt;Please Enter Tower height...&lt;/p&gt;
&lt;p style="color: rgb(51, 51, 255);"&gt;3&lt;/p&gt;
&lt;p&gt;steps: 1&lt;/p&gt;
&lt;p&gt;Move 1 from A to B&lt;/p&gt;
&lt;p&gt;steps: 2&lt;/p&gt;
&lt;p&gt;Move 2 from A to C&lt;/p&gt;
&lt;p&gt;steps: 3&lt;/p&gt;
&lt;p&gt;Move 1 from B to C&lt;/p&gt;
&lt;p&gt;steps: 4&lt;/p&gt;
&lt;p&gt;Move 3 from A to B&lt;/p&gt;
&lt;p&gt;steps: 5&lt;/p&gt;
&lt;p&gt;Move 1 from C to A&lt;/p&gt;
&lt;p&gt;steps: 6&lt;/p&gt;
&lt;p&gt;Move 2 from C to B&lt;/p&gt;
&lt;p&gt;steps: 7&lt;/p&gt;
&lt;p&gt;Move 1 from A to B&lt;/p&gt;




&lt;p&gt; &lt;span style="font-weight: bold;"&gt;Notes: &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; Submit your HanoiTower.java file to &lt;span style="color: rgb(255, 0, 0);"&gt;espiggy@gmail.com&lt;/span&gt; before &lt;span style="color: rgb(255, 0, 0);"&gt;4:00pm&lt;/span&gt;.  No late submission accepted!  &lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-7101825820301674982?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/7101825820301674982/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/12/section-005-lab-test-03.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/7101825820301674982?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/7101825820301674982?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/12/section-005-lab-test-03.html" title="SECTION 005: Lab test 03" /><author><name>Yi Xian</name><uri>http://www.blogger.com/profile/02168279713204225202</uri><email>espiggy@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="11183617117784671576" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_TX8m2mjYJTA/SxViOCkJj7I/AAAAAAAAFjg/zWc2srewdSg/s72-c/hanoi4.gif" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEMAQ3g5cCp7ImA9WxNaF0s.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-2709069426818898338</id><published>2009-11-19T13:20:00.009-05:00</published><updated>2009-12-02T10:07:22.628-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-02T10:07:22.628-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="lab" /><title>Lab 22</title><content type="html">Question 8 on Page 850.

&lt;p&gt; Hint: &lt;/p&gt;

&lt;p&gt; here is the code of class Spices . &lt;/p&gt;

&lt;pre class="prettyprint lang-java"&gt;

import java.util.Scanner;

/**
 Class for data on endangered species.
*/
public class Species
{
    private String name;
    private int population;
    private double growthRate;

    public void readInput( )
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("What is the species' name?");
        name = keyboard.nextLine( );

        System.out.println(
                      "What is the population of the species?");
        population = keyboard.nextInt( );
        while (population &lt; 0)
        {
            System.out.println("Population cannot be negative.");
            System.out.println("Reenter population:");
            population = keyboard.nextInt( );
        }

        System.out.println("Enter growth rate (% increase per year):");
       growthRate = keyboard.nextDouble( );
    }

    public void writeOutput( )
    {
         System.out.println("Name = " + name);
         System.out.println("Population = " + population);
         System.out.println("Growth rate = " + growthRate + "%");
    }

    /**
     Precondition: years is a nonnegative number.
     Returns the projected population of the calling object
     after the specified number of years.
    */
    public int predictPopulation(int years)
    {
  int result = 0;
        double populationAmount = population;
        int count = years;
        while ((count &gt; 0) &amp;&amp; (populationAmount &gt; 0))
        {
            populationAmount = (populationAmount +
                          (growthRate / 100) * populationAmount);
            count--;
        }
        if (populationAmount &gt; 0)
            result = (int)populationAmount;
 
        return result;
    }

    public void setSpecies(String newName, int newPopulation,
                           double newGrowthRate)
    {
        name = newName;
        if (newPopulation &gt;= 0)
            population = newPopulation;
        else
        {
            System.out.println("ERROR: using a negative population.");
            System.exit(0);
        }
        growthRate = newGrowthRate;
    }

    public String getName( )
    {
        return name;
    }

    public int getPopulation( )
    {
        return population;
    }

    public double getGrowthRate( )
    {
        return growthRate;
    }

    public boolean equals(Species otherObject)
    {
        return (name.equalsIgnoreCase(otherObject.name)) &amp;&amp;
               (population == otherObject.population) &amp;&amp;
               (growthRate == otherObject.growthRate);
    }
}

&lt;/pre&gt;

&lt;p&gt;Here is the code from Listing 12.5 on Page 821. &lt;/p&gt;



&lt;pre class="prettyprint lang-java"&gt;


public class StringLinkedListSelfContained
{
    private ListNode head;

    public StringLinkedListSelf( )
    {
        head = null;
    }

    /**
     Displays the data on the list.
    */
    public void showList( )
    {
        ListNode position = head;
        while (position != null)
        {
            System.out.println(position.data);
            position = position.link;
        }
    }

    /**
     Returns the number of nodes on the list.
    */
    public int length( )
    {
        int count = 0;
        ListNode position = head;
        while (position != null)
        {
            count++;
            position = position.link;
        }
        return count;
    }

    /**
     Adds a node containing the data addData at the 
     start of the list.
    */
    public void addANodeToStart(String addData)
    {
        head = new ListNode(addData, head);
    }

    /**
     Deletes the first node on the list.
    */
    public void deleteHeadNode( )
    {
        if (head != null)
            head = head.link;
        else
        {
            System.out.println("Deleting from an empty list.");
            System.exit(0);
        }
    }

    /**
     Sees whether target is on the list.
    */
    public boolean onList(String target)
    {
        return find(target) != null;
    }

    // Returns a reference to the first node containing the
    // target data. If target is not on the list, returns null.
 private ListNode find(String target)
    {
  boolean found = false;
        ListNode position = head;
        while ((position != null) &amp;&amp; !found)
        {
            String dataAtPosition = position.data;
            if (dataAtPosition.equals(target))
    found = true;
   else
    position = position.link;
        }

        return position;
    }

    public String[] toArray( )
    {
        String[] anArray = new String[length( )];

        ListNode position = head;
        int i = 0;
        while (position != null)
        {
            anArray[i] = position.data;
            i++;
            position = position.link;
        }

        return anArray;
    }

    private class ListNode
    {
        private String   data;
        private ListNode link;
  
        public ListNode( )
        {
            link = null;
            data = null;
        }
  
        public ListNode(String newData, ListNode linkValue)
        {
            data = newData;
            link = linkValue;
        }
    }
}

 &lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-2709069426818898338?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/2709069426818898338/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/11/lab-22.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2709069426818898338?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2709069426818898338?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/11/lab-22.html" title="Lab 22" /><author><name>Yi Xian</name><uri>http://www.blogger.com/profile/02168279713204225202</uri><email>espiggy@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="11183617117784671576" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;C0IEQXc_eyp7ImA9WxNbFUg.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-2939037131975263472</id><published>2009-11-17T12:30:00.016-05:00</published><updated>2009-11-18T08:38:20.943-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-18T08:38:20.943-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="homework" /><category scheme="http://www.blogger.com/atom/ns#" term="solution" /><title>Homework 8 Solution</title><content type="html">Below is my solution for the Binary Search Tree:

&lt;pre class="prettyprint lang-java"&gt;
public class BinarySearchTree {

 private BinarySearchTree left;
 
 private BinarySearchTree right;
 
 private int data;
 
 public BinarySearchTree() {
  left = null;
  right = null;
 }
 
 /** Create a tree that consists of just one node with no children. */
 public BinarySearchTree(int data) {
  left = null;
  right = null;
  this.data = data;
 }
 
 /** Adds new number n to this BinarySearchTree, placing it in its correct place.
  * 
  * @param n the number to be added
  */
 public void add (int n) {
  if (n &lt;= data) {
   if (left != null) 
    left.add(n);
   else 
    left = new BinarySearchTree(n);
  }
  else { // n &gt; data
   if (right != null) 
    right.add(n);
   else 
    right = new BinarySearchTree(n);
  }
 }
 
 /** Returns the maximum number in this tree. */
 public int max() {
  if (right == null)
   return data;
  return right.max();
 }
 
 /** Returns the height of this tree. */
 public int height() {
  //The base cases are when a child is null.
  return 1 + Math.max((left == null ? 0: left.height()), 
       (right == null ? 0: right.height()));
 }
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-2939037131975263472?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/2939037131975263472/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/11/homework-8-solution.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2939037131975263472?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2939037131975263472?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/11/homework-8-solution.html" title="Homework 8 Solution" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;A0cEQX86fSp7ImA9WxNbFEo.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-1716991525363651433</id><published>2009-11-17T12:30:00.013-05:00</published><updated>2009-11-17T12:30:00.115-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-17T12:30:00.115-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="homework" /><title>Homework 9: Sets</title><content type="html">&lt;p&gt;For this homework you will implement a simple &lt;b&gt;generic &lt;a href="http://en.wikipedia.org/wiki/Set_%28computer_science%29"&gt;Set&lt;/a&gt; class&lt;/b&gt;. That is, you will implement a &lt;code&gt;class Set&amp;lt;T&amp;gt;&lt;/code&gt; using Java's &lt;code&gt;ArrayList&lt;/code&gt; as the data member that holds the values. &lt;/p&gt; 

&lt;p&gt;A set is defined as a collection of elements (in our case, all of the same type) such that every element appears at most once in the collection. The methods your &lt;code&gt;Set&amp;lt;T&amp;gt;&lt;/code&gt; must implement are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;Set()&lt;/code&gt; the constructor takes no arguments and creates an empty set.&lt;/li&gt;

&lt;li&gt;&lt;code&gt;String toString()&lt;/code&gt; returns a string with all the elements of this set in printed form, as usual.&lt;/li&gt;

&lt;li&gt;&lt;code&gt;void add(T x)&lt;/code&gt; adds element &lt;code&gt;x&lt;/code&gt; to the set. If &lt;code&gt;x&lt;/code&gt; is already in the set then it does nothing.&lt;/li&gt;

&lt;li&gt;&lt;code&gt;boolean contains(T x)&lt;/code&gt; returns true if the set contains the element &lt;code&gt;x&lt;/code&gt;, false otherwise.&lt;/li&gt;

&lt;li&gt;&lt;code&gt;void add(Set&amp;lt;T&amp;gt; other)&lt;/code&gt; adds the complete contents of the set &lt;code&gt;other&lt;/code&gt; to this set.&lt;/li&gt;

&lt;li&gt;&lt;code&gt;void subtract(Set&amp;lt;T&amp;gt; other)&lt;/code&gt; removes every element of &lt;code&gt;other&lt;/code&gt; that is in this set.&lt;/li&gt;

&lt;li&gt;&lt;code&gt;boolean isSubset(Set&amp;lt;T&amp;gt; other)&lt;/code&gt; returns true if and only if this set is a subset of &lt;code&gt;other&lt;/code&gt;, that is, if all the elements in this set are also contained in &lt;code&gt;other&lt;/code&gt;.&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;You will also implement some test cases in your &lt;code&gt;main()&lt;/code&gt; to ensure that your class works correctly. This homework is due on &lt;b&gt;Tuesday, November 24 @noon&lt;/b&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-1716991525363651433?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/1716991525363651433/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/11/homework-9-sets.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/1716991525363651433?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/1716991525363651433?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/11/homework-9-sets.html" title="Homework 9: Sets" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEMBR3k9cSp7ImA9WxNaF0s.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-2681397353415050367</id><published>2009-11-17T12:17:00.001-05:00</published><updated>2009-12-02T10:07:36.769-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-02T10:07:36.769-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="lab" /><title>Lab 21</title><content type="html">Question 1 on Page 849.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-2681397353415050367?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/2681397353415050367/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/11/lab-21.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2681397353415050367?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2681397353415050367?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/11/lab-21.html" title="Lab 21" /><author><name>Yi Xian</name><uri>http://www.blogger.com/profile/02168279713204225202</uri><email>espiggy@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="11183617117784671576" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CkUDR30yfip7ImA9WxNbEEg.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-4019609491727856862</id><published>2009-11-12T13:18:00.003-05:00</published><updated>2009-11-12T13:24:36.396-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-12T13:24:36.396-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="lab" /><title>Lab 20</title><content type="html">Given an array of &lt;span style="font-weight:bold;"&gt;unsorted&lt;/span&gt; integers, implement a &lt;span style="font-weight:bold;"&gt;recursive&lt;/span&gt; method to find the minimal value. 
&lt;br&gt;&lt;/br&gt;
Input: 3, 7, 12, -3, 6, 0, -1, 23
&lt;br&gt;&lt;/br&gt;
Output: -3
&lt;br&gt;&lt;/br&gt;
(Hint: you can refer to the merge sort as listing 11.7)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-4019609491727856862?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/4019609491727856862/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/11/lab-20.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/4019609491727856862?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/4019609491727856862?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/11/lab-20.html" title="Lab 20" /><author><name>Xu Sun</name><uri>http://www.blogger.com/profile/13502695489105587650</uri><email>xusun09@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14239689565294866887" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CkIAQnc_fSp7ImA9WxNbEEk.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-3893430358324219251</id><published>2009-11-12T10:42:00.000-05:00</published><updated>2009-11-12T10:42:23.945-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-12T10:42:23.945-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="lecture" /><title>Chapter 12: Generics</title><content type="html">Below is the screencast for Chapter 12 which talks about generics. The chapter also covers dynamic data structures but we will not be focusing on those, so you can skip those sections if you want, or you can read them and be ready for CSCE 146.

&lt;center&gt;
&lt;object width="640" height="360"&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="allowscriptaccess" value="always" /&gt;&lt;param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=7573408&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=00ADEF&amp;amp;fullscreen=1" /&gt;&lt;embed src="http://vimeo.com/moogaloop.swf?clip_id=7573408&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=00ADEF&amp;amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="360"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;p&gt;&lt;a href="http://vimeo.com/7573408"&gt;CSCE 145: Chapter 12&lt;/a&gt; from &lt;a href="http://vimeo.com/jmvidal"&gt;Jose Vidal&lt;/a&gt; on &lt;a href="http://vimeo.com"&gt;Vimeo&lt;/a&gt;.&lt;/p&gt;
&lt;/center&gt;

You should watch the screencast before class on &lt;b&gt;Tuesday, November 17&lt;/b&gt;. Here are the slides from the textbook:

&lt;center&gt;
&lt;iframe src="http://docs.google.com/present/embed?id=dhh5qxv8_8687w95gjsg" frameborder="0" width="410" height="342"&gt;&lt;/iframe&gt;
&lt;/center&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-3893430358324219251?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/3893430358324219251/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/11/chapter-12-generics.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/3893430358324219251?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/3893430358324219251?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/11/chapter-12-generics.html" title="Chapter 12: Generics" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DU8EQX8_fip7ImA9WxNUGEo.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-2379108658944980934</id><published>2009-11-10T13:30:00.001-05:00</published><updated>2009-11-10T13:30:00.146-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-10T13:30:00.146-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="homework" /><category scheme="http://www.blogger.com/atom/ns#" term="solution" /><title>Homework 7 Solution</title><content type="html">Below is my solution for the Field Notebook homework:

&lt;pre class="prettyprint lang-java"&gt;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;
import java.util.Scanner;


public class Notebook {

 private Reading[] reading;

 private int nextIndex = 0;

 /** Maximum number of readings. */
 private static final int SIZE = 100;

 public Notebook(){
  reading = new Reading[SIZE]; 
 }

 /**
  * Creates a notebook by reading its contents from the given file.
  * @param filename
  * @throws IOException
  */
 public Notebook(String filename) throws IOException {
  try {
   ObjectInputStream input = new ObjectInputStream (new FileInputStream(filename));
   nextIndex = input.readInt();
   reading = (Reading[])input.readObject();
   input.close();
  }  catch (ClassNotFoundException e) {
   System.out.println("ERROR: File corrupted.");
   e.printStackTrace();
  }
 }

 /**
  * Adds a reading to the notebook
  * @param species name of the species
  * @param count how many you saw
  * @param comment 
  * @throws Exception if the notebook gets too big
  */
 public void addReading(String species, int count, String comment) throws Exception{
  //The right thing to do is use a data structure that expands as needed, but that's CSCE 146
  //  so we just crash.
  try {
   if (nextIndex &gt;= SIZE) 
    throw new Exception("Too many readings!");
   reading[nextIndex] = new Reading(new Date(), species, count, comment);
   nextIndex++;
  }
  catch (NegativeCountException e) {
   System.out.println("Sorry, no negative animals allowed.");
  }
 }

 public String toString(){
  String result = "";
  for(int i=0; i&lt; nextIndex; i++){
   result += reading[i].toString() + "\n";
  }
  return result;
 }

 /**
  * Write this notebook out to a file. It can be read back using the constructor.
  * @param filename name of the file
  * 
  */
 public void writeToFile(String filename) {
  try {
   ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(filename));
   out.writeInt(nextIndex);
   out.writeObject(reading);
   out.close();
  } catch (FileNotFoundException e) {
   System.out.println("ERROR: No such file. Did not write.");
  } catch (IOException e) {
   System.out.println("ERROR: IO. Did not write to file.");
  }
 }

 public static void main(String[] args) throws Exception {

  Scanner keyboard = new Scanner(System.in);
  Notebook notebook = new Notebook();


  while (true){
   System.out.println("Command list: \n");
   System.out.println("r - enter new Reading");
   System.out.println("l - List all readings");
   System.out.println("o - Open file with readings");
   System.out.println("w - Write readings to a file");
   System.out.println("q - Quit");
   System.out.print("\nEnter command:");
   String command = keyboard.nextLine();

   if (command.equalsIgnoreCase("r")) {
    System.out.print("Species name:");
    String species = keyboard.nextLine();
    System.out.print("Count:");
    int count = Integer.parseInt(keyboard.nextLine());
    System.out.print("Comment:");
    String comment = keyboard.nextLine();
    notebook.addReading(species, count, comment);
   }
   else if (command.equalsIgnoreCase("l")) {
    System.out.println(notebook);   
   }
   else if (command.equalsIgnoreCase("o")) {
    System.out.print("Enter name of file to read:");
    String filename = keyboard.nextLine();
    try {
     notebook = new Notebook(filename);
    }
    catch (FileNotFoundException e) {
     System.out.println("ERROR: File " + filename +  " does not exists.");
    }
   }
   else if (command.equalsIgnoreCase("w")) {
    System.out.print("Enter name of file to write to:");
    String filename = keyboard.nextLine();
    notebook.writeToFile(filename);    
   }
   else if (command.equalsIgnoreCase("q")) {
    System.out.println("Bye bye.");
    System.exit(0);
   }
  }


 }

}

import java.io.Serializable;
import java.util.Date;

public class Reading implements Serializable {

 private Date date;

 private String species;

 private int count;

 private String comment;

 public Reading(Date date, String species, int count, String comment) throws NegativeCountException {
  super();
  if (count &lt; 0)
   throw new NegativeCountException("There are no negative animals you dummy.");
  this.date = date;
  this.species = species;
  this.count = count;
  this.comment = comment;
 }

 public String toString() {
  return date + "\t" + species + "\t" + count + "\t" + comment;
 }

}


public class NegativeCountException extends Exception {

 public NegativeCountException(String m) {
  super(m);
 }

}






&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-2379108658944980934?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/2379108658944980934/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/11/homework-7-solution.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2379108658944980934?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2379108658944980934?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/11/homework-7-solution.html" title="Homework 7 Solution" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEMCRn8zfCp7ImA9WxNaF0s.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-1912335635313727544</id><published>2009-11-10T13:01:00.003-05:00</published><updated>2009-12-02T10:07:47.184-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-02T10:07:47.184-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="lab" /><title>Lab 19</title><content type="html">&lt;p&gt;Question 8 on page 786. &lt;/p&gt;

&lt;p&gt;Hint: refer to binary search class and demo on page 777-778. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-1912335635313727544?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/1912335635313727544/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/11/lab-19.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/1912335635313727544?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/1912335635313727544?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/11/lab-19.html" title="Lab 19" /><author><name>Yi Xian</name><uri>http://www.blogger.com/profile/02168279713204225202</uri><email>espiggy@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="11183617117784671576" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CU4MRX4-fCp7ImA9WxNUGEo.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-2621193231951816041</id><published>2009-11-10T12:20:00.012-05:00</published><updated>2009-11-10T12:26:24.054-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-10T12:26:24.054-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="homework" /><title>Homework 8: Binary Search Trees</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/_mMuRlDPULDs/SvhXN_Sf_NI/AAAAAAAACIg/Xz5qTRAoSvM/s1600-h/300px-Binary_search_tree.svg.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/_mMuRlDPULDs/SvhXN_Sf_NI/AAAAAAAACIg/Xz5qTRAoSvM/s320/300px-Binary_search_tree.svg.png" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
A &lt;a href="http://en.wikipedia.org/wiki/Binary_search_tree"&gt;Binary Search Tree&lt;/a&gt; is a very commonly used data structure, about which you will learn much more in 146, that stores numbers in 
a tree where every node has two children (thus, binary). Each node contains a number. All the numbers on the &lt;em&gt;left&lt;/em&gt; branch of a node are smaller than that node and, similarly, all the numbers on the &lt;em&gt;right&lt;/em&gt; branch of a node are bigger than the node. The figure on the right shows an example.&lt;br /&gt;

Below you will find a partial implementation of a binary search tree with three methods missing: &lt;code&gt;add&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt;, and &lt;code&gt;height&lt;/code&gt;. For this homework you will implement these methods.

&lt;pre class="prettyprint lang-java"&gt;
public class BinarySearchTree {

 private BinarySearchTree left;
 
 private BinarySearchTree right;
 
 private int data;
 
 public BinarySearchTree() {
  left = null;
  right = null;
 }
 
 /** Create a tree that consists of just one node with no children. */
 public BinarySearchTree(int data) {
  left = null;
  right = null;
  this.data = data;
 }
 
 /** Adds new number n to this BinarySearchTree, placing it in its correct place.
  * 
  * @param n the number to be added
  */
 public void add (int n) {
           //TODO
 }
 
 /** Returns the maximum number in this tree. */
 public int max() {
           //TODO
 }
 
 /** Returns the height of this tree. */
 public int height() {
           //TODO
 }
 
 public String toString() {
  return toString("");
 }
 
 public String toString(String prefix) {
  String result = "";
  if (right != null)
   result += right.toString(prefix + "-");
  else
   result += prefix + "- *\n"; 
  
  result += prefix + " " + data + "\n";
  
  if (left != null)
   result += left.toString(prefix + "-");
  else
   result += prefix + "- *\n";
    
  return result;  
 }
 
 
 public static void main(String[] args) {
  BinarySearchTree tree = new BinarySearchTree(8);
  tree.add(3);
  tree.add(10);
  tree.add(1);
  tree.add(6);
  tree.add(14);
  tree.add(4);
  tree.add(7);
  tree.add(13);
  System.out.println(tree);
  System.out.println("Max=" + tree.max());
  System.out.println("Height=" + tree.height());

 }
}
&lt;/pre&gt;

The &lt;code&gt;main&lt;/code&gt; method shown above constructs the tree shown in the figure. After you properly implement the methods, that &lt;code&gt;main&lt;/code&gt; will run and will print out:

&lt;pre&gt;
--- *
-- 14
---- *
--- 13
---- *
- 10
-- *
 8
---- *
--- 7
---- *
-- 6
---- *
--- 4
---- *
- 3
--- *
-- 1
--- *

Max=14
Height=4
&lt;/pre&gt;

This homework is due &lt;b&gt;Tuesday, November 17 at noon&lt;/b&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-2621193231951816041?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/2621193231951816041/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/11/homework-8-binary-search-trees.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2621193231951816041?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2621193231951816041?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/11/homework-8-binary-search-trees.html" title="Homework 8: Binary Search Trees" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_mMuRlDPULDs/SvhXN_Sf_NI/AAAAAAAACIg/Xz5qTRAoSvM/s72-c/300px-Binary_search_tree.svg.png" height="72" width="72" /><thr:total>2</thr:total></entry><entry gd:etag="W/&quot;DEIGRHs-fyp7ImA9WxNUFEg.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-7206442880633585694</id><published>2009-11-05T13:12:00.001-05:00</published><updated>2009-11-05T16:28:45.557-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-05T16:28:45.557-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="lab" /><title>Lab 18</title><content type="html">&lt;p&gt;Question 1 on Page 744. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: only use a &lt;span style="color:#cc0000;"&gt;text file&lt;/span&gt;.&lt;/strong&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-7206442880633585694?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/7206442880633585694/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/11/lab-18.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/7206442880633585694?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/7206442880633585694?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/11/lab-18.html" title="Lab 18" /><author><name>Yi Xian</name><uri>http://www.blogger.com/profile/02168279713204225202</uri><email>espiggy@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="11183617117784671576" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEQARng9fCp7ImA9WxNUFE4.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-5519964001359310342</id><published>2009-11-05T10:51:00.001-05:00</published><updated>2009-11-05T10:52:27.664-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-05T10:52:27.664-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="lecture" /><title>Chapter 11: Recursion</title><content type="html">Chapter 11 deals with the topic of recursion. Recursion is not a language feature, it is simply having a method call itself. All programming languages are capable of recursion. Recursion is a technique that makes certain algorithms (which we do not cover in this class) much easier to write and understand.

&lt;center&gt;
&lt;object width="640" height="360"&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="allowscriptaccess" value="always" /&gt;&lt;param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=7453429&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=00ADEF&amp;amp;fullscreen=1" /&gt;&lt;embed src="http://vimeo.com/moogaloop.swf?clip_id=7453429&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=00ADEF&amp;amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="360"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;p&gt;&lt;a href="http://vimeo.com/7453429"&gt;CSCE 145: Chapter 11&lt;/a&gt; from &lt;a href="http://vimeo.com/jmvidal"&gt;Jose Vidal&lt;/a&gt; on &lt;a href="http://vimeo.com"&gt;Vimeo&lt;/a&gt;.&lt;/p&gt;
&lt;/center&gt;

You will need to have watched the above screencast by &lt;b&gt;Tuesday, November 10, before class&lt;/b&gt;. Here are the slides from the textbook:

&lt;center&gt;
&lt;iframe src="http://docs.google.com/present/embed?id=dhh5qxv8_8413vbxx8dr" frameborder="0" width="410" height="342"&gt;&lt;/iframe&gt;
&lt;/center&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-5519964001359310342?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/5519964001359310342/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/11/chapter-11-recursion.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/5519964001359310342?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/5519964001359310342?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/11/chapter-11-recursion.html" title="Chapter 11: Recursion" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEIHR3g9fSp7ImA9WxNUFEg.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-2745847837483164440</id><published>2009-11-03T13:48:00.001-05:00</published><updated>2009-11-05T16:28:56.665-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-05T16:28:56.665-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="lab" /><title>Lab 17</title><content type="html">Qestion 2 on Page 673.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-2745847837483164440?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/2745847837483164440/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/11/lab-17_03.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2745847837483164440?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2745847837483164440?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/11/lab-17_03.html" title="Lab 17" /><author><name>Yi Xian</name><uri>http://www.blogger.com/profile/02168279713204225202</uri><email>espiggy@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="11183617117784671576" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;C0cEQXs-eyp7ImA9WxNVGU4.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-5499343724801867730</id><published>2009-10-30T15:30:00.002-04:00</published><updated>2009-10-30T15:30:00.553-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-30T15:30:00.553-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="lecture" /><title>Chapter 10 Lecture</title><content type="html">Below is the screencast for the chapter 10 which deals with reading and writing streams to files. I/O operations like these are slightly different on every programming language, but the basic ideas are the same.

&lt;center&gt;
&lt;object width="640" height="360"&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="allowscriptaccess" value="always" /&gt;&lt;param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=7328987&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=00ADEF&amp;amp;fullscreen=1" /&gt;&lt;embed src="http://vimeo.com/moogaloop.swf?clip_id=7328987&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=00ADEF&amp;amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="360"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;p&gt;&lt;a href="http://vimeo.com/7328987"&gt;CSCE 145: Chapter 10&lt;/a&gt; from &lt;a href="http://vimeo.com/jmvidal"&gt;Jose Vidal&lt;/a&gt; on &lt;a href="http://vimeo.com"&gt;Vimeo&lt;/a&gt;.&lt;/p&gt;
&lt;/center&gt;

&lt;p&gt;You must have watched the screencast by &lt;b&gt;Tuesday, November 3&lt;/b&gt; before class. The textbook slides are below.&lt;/p&gt;

&lt;center&gt;
&lt;iframe src="http://docs.google.com/present/embed?id=dhh5qxv8_803fwrptg3j" frameborder="0" width="410" height="342"&gt;&lt;/iframe&gt;
&lt;/center&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-5499343724801867730?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/5499343724801867730/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/10/chapter-10-lecture.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/5499343724801867730?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/5499343724801867730?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/10/chapter-10-lecture.html" title="Chapter 10 Lecture" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DE4DSHoyeSp7ImA9WxNVGU8.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-7697577837608629354</id><published>2009-10-30T14:20:00.001-04:00</published><updated>2009-10-30T14:22:59.491-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-30T14:22:59.491-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="homework" /><title>Homework 7: Field Notebook</title><content type="html">&lt;img style="width:400px;float:right" src="http://upload.wikimedia.org/wikipedia/commons/thumb/d/db/Cairns_birdwing_-_melbourne_zoo.jpg/800px-Cairns_birdwing_-_melbourne_zoo.jpg"/&gt;
For this homework you will implement a minimal field notebook, as might be used by a bird or butterfly watcher on the field (on her Android phone, one presumes). Your application will need to implement at least three classes:

&lt;ol&gt;

&lt;li&gt;&lt;code&gt;Reading&lt;/code&gt; is a specific observation that the user makes. This class has data members&lt;ol&gt;
&lt;li&gt;&lt;code&gt;date&lt;/code&gt; of type &lt;code&gt;Date&lt;/code&gt;, the date of the reading, which you will assign automatically to the current time.&lt;/li&gt;

&lt;li&gt;&lt;code&gt;species&lt;/code&gt; is a &lt;code&gt;String&lt;/code&gt; which is the name of the species of animal the user saw.&lt;/li&gt;

&lt;li&gt;&lt;code&gt;count&lt;/code&gt; is an &lt;code&gt;int&lt;/code&gt; that is the number of animals the user saw.&lt;/li&gt;

&lt;li&gt;&lt;code&gt;comment&lt;/code&gt; a &lt;code&gt;String&lt;/code&gt; comment
&lt;/ol&gt;&lt;/li&gt;

&lt;li&gt;&lt;code&gt;Notebook&lt;/code&gt; is a collection of up to 100 readings. It should support, adding a new reading, printing, saving to a file, and reading back from a file.&lt;/li&gt;

&lt;li&gt;&lt;code&gt;NegativeCountException&lt;/code&gt; is an &lt;code&gt;Exception&lt;/code&gt; that you will raise if the user ever tries to enter a negative number of animals. Your program will throw this exception and also catch it, so the program does not crash.

&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;
Your program will support the saving of the whole notebook to a file and the subsequent loading of a notebook from a file. The whole thing will be controlled via a text-based interface, as such:
&lt;/p&gt;
&lt;pre&gt;
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:r
Species name:swallowtails
Count:3
Comment:Fluttering in the sunshine.
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:r
Species name:Jezebel
Count:11
Comment:Hard to count in the daylight.
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:l
Fri Oct 30 14:11:31 EDT 2009 swallowtails 3 Fluttering in the sunshine.
Fri Oct 30 14:12:02 EDT 2009 Jezebel 11 Hard to count in the daylight.

Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:r
Species name:Duke of Burgundy
Count:1
Comment:Did not expect to see this one here!
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:l
Fri Oct 30 14:11:31 EDT 2009 swallowtails 3 Fluttering in the sunshine.
Fri Oct 30 14:12:02 EDT 2009 Jezebel 11 Hard to count in the daylight.
Fri Oct 30 14:12:37 EDT 2009 Duke of Burgundy 1 Did not expect to see this one here!

Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:w
Enter name of file to write to:notebook.dat
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:l
Fri Oct 30 14:11:31 EDT 2009 swallowtails 3 Fluttering in the sunshine.
Fri Oct 30 14:12:02 EDT 2009 Jezebel 11 Hard to count in the daylight.
Fri Oct 30 14:12:37 EDT 2009 Duke of Burgundy 1 Did not expect to see this one here!

Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:q
Bye bye. //at this point the program stops.

//we start it again
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:l

Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:o
Enter name of file to read:notebook.dat
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:l
Fri Oct 30 14:11:31 EDT 2009 swallowtails 3 Fluttering in the sunshine.
Fri Oct 30 14:12:02 EDT 2009 Jezebel 11 Hard to count in the daylight.
Fri Oct 30 14:12:37 EDT 2009 Duke of Burgundy 1 Did not expect to see this one here!

Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:r
Species name:Speckled wood
Count:200
Comment:A gaggle of butterflies.
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:l
Fri Oct 30 14:11:31 EDT 2009 swallowtails 3 Fluttering in the sunshine.
Fri Oct 30 14:12:02 EDT 2009 Jezebel 11 Hard to count in the daylight.
Fri Oct 30 14:12:37 EDT 2009 Duke of Burgundy 1 Did not expect to see this one here!
Fri Oct 30 14:14:53 EDT 2009 Speckled wood 200 A gaggle of butterflies.

Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:r
Species name:zabulon skipper
Count:-1
Comment:lets try this
Sorry, no negative animals allowed.
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:o
Enter name of file to read:thisfilenamedoesnotexist.dat
ERROR: File thisfilenamedoesnotexist.dat does not exists.
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:q
Bye bye.

&lt;/pre&gt;

&lt;p&gt;This homework is &lt;b&gt;due Tuesday, November 10 @noon&lt;/b&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-7697577837608629354?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/7697577837608629354/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/10/homework-7-field-notebook.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/7697577837608629354?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/7697577837608629354?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/10/homework-7-field-notebook.html" title="Homework 7: Field Notebook" /><author><name>Jose M Vidal</name><uri>http://www.blogger.com/profile/16605820980157120553</uri><email>jmvidal@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="17280427899840422606" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;AkIARH48eyp7ImA9WxNVGE4.&quot;"><id>tag:blogger.com,1999:blog-5686477000239873431.post-2618512535631705419</id><published>2009-10-29T13:24:00.002-04:00</published><updated>2009-10-29T13:49:05.073-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-29T13:49:05.073-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="lab" /><title>Lab test 2 review</title><content type="html">Today we will have review for lab test 2.

No lab assignment.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5686477000239873431-2618512535631705419?l=www.csce145.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.csce145.com/feeds/2618512535631705419/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.csce145.com/2009/10/lab-test-2-review.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2618512535631705419?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5686477000239873431/posts/default/2618512535631705419?v=2" /><link rel="alternate" type="text/html" href="http://www.csce145.com/2009/10/lab-test-2-review.html" title="Lab test 2 review" /><author><name>Yi Xian</name><uri>http://www.blogger.com/profile/02168279713204225202</uri><email>espiggy@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="11183617117784671576" /></author><thr:total>0</thr:total></entry></feed>
