Computer Science 15-110, Spring 2010
Recitation for Week #9


  1. Return Midterm
  2. CA-Directed Lab
    1. printInReverse
    2. reverse
    3. reverseInPlace
  3. Student-Directed (Collaborative) Lab
    1. disjoint
    2. Fraction class
  4. Review Hw7 (time permitted)

  1. Return Midterm
    CA's will return the midterm.  We already reviewed highlights in class, so we will not use recitation time to review the midterm further.  Students needing deeper review of the material should set up a separate meeting with their CA or instructor.
     
  2. CA-Directed Lab
    1. printInReverse
      Write a void method named printInReverse that takes no parameters and reads in an int n followed by n more ints, then prints out those n ints in reverse.  Do nothing if n is non-positive.
       
    2. reverse
      Write a method named reverse that takes an array and returns a new array that is the same as the original array but in reverse. You may not alter the original array.
       
    3. reverseInPlace
      Write a void method named reverseInPlace that takes an array and destructively reverses that array.  You may not create another temporary array.
       
  3. Student-Directed (Collaborative) Lab
    1. disjoint
      Write a method named disjoint that takes two arrays of ints and returns true if they are disjoint -- that is, if no ints occur in both arrays.  Be sure to handle null arrays and empty arrays correctly!
       
    2. Fraction class
      Without referring to the class notes, reconstruct the Fraction class as we wrote it on the first day of "Getting Started with Writing Classes".  Here is an excerpt from the class notes to get you started:

      ===================================================================

      In class this week we are starting to write our own classes.

      The first class we are writing is a simple Fraction class.  We would like the following code to work:

        // We want this, but can't have it (darn!)
        public static void main(String[] args) {
          Fraction f1 = 2/3;
          Fraction f2 = 3/9;
          Fraction f3 = f1*f2;
          System.out.println(f1);
          System.out.println(f2);
          System.out.println(f3);
        }

      Unfortunately, we cannot overload the / and * operators highlighted above to work this way (you can in some other languages, but not in Java).

      So instead we'll settle on this version, which is similar but written in a way that we actually can support:

        // Compare this to the version above
        public static void main(String[] args) {
          Fraction f1 = new Fraction(2,3);
          Fraction f2 = new Fraction(3,9);
          Fraction f3 = f1.times(f2);
          System.out.println(f1);
          System.out.println(f2);
          System.out.println(f3);
        }

      And here is the code we wrote in class (warts and all) to do it:

      (This is what you will write in recitation!)

      ===================================================================
       

  4. Review Hw7 (time permitting)
    Time permitting, CA's will briefly review highlights of hw7.  Students needing deeper review of the material should set up a separate meeting with their CA or instructor.

carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem