Tina Comston
Comp-111 Week 13
Franklin University
Week 13
Preparation
    • Read Chapter 8 (sections 8.3 - 8.6) in the COMP 111 Reading Guide.
      Guided Learning Activity
      Assignment
      • Problem 1
      Mutable versus Immutable Classes

      A few weeks ago mutable (mutator) versus immutable (accessor) methods were discussed.   A mutable method makes changes to the instance variables of an object.  An immutable method does not.

      It is possible to have both mutable and immutable methods within the same object.

      When it comes to classes, an immutable class contains only immutable methods - other than the constructor.  The constructor will create the object, setting the instance variables to their value, but once created the instance variables cannot be changed.  The class contain only immutable methods.

      A mutable class, on the other hand, contains does allow for modification of the instance variables.  It contains mutator methods and most likely also contains immutable methods (accessors).

      To learn more:
      http://www.java-questions.com/ImmutableClass-interview-questions.html
      • Problem 2
      Designing Classes

      When presented with a problem and trying to determine what classes are needed, think nouns.  A class is a computer version of a real world entity.  A method, on the other hand, is an action, think verb.  

      Consider a Dog class - a dog is a real world entity.  Get age - that's an action.  Bark - action, Set - action.  Dog would be a class, the others would be methods.

      Dependency Diagrams

      Open lab 4 in BlueJ.  Take a look at the initial screen where all of the classes are listed  - that is a dependency diagram.  Note the dashed lines with arrows going from one class to another?  That indicates a dependency.  

      If you reference a class within another class - that indicates a dependency.  For example, if there is a Dog class and within the class there is a Date object for the birth date, the Dog class will be dependent upon the Date class.

      In a dependency diagram this would be represented by a dashed line going from the Dog class and pointing to the Date class.

      To learn more:
      http://ourownjava.com/uml/uml-class-diagram-dependencyuses/
      • Problem 3
      Using the Sort Algorithms
          For a review of the algorithms, see Week 12 Hints & Tips.

      Before you can use the sort algorithms you first need to determine the following:
      • Array or ArrayList
        • The algorithms are written for an array.  If you have an ArrayList, you will need to convert all references to the array to be a reference to an ArrayList.
          • If you are retrieving a value from an array with arr[i], you would need to use the ArrayList .get() method.
          • If you are changing a value of an array with arr[i], you would need to use the ArrayList  .set() method.
      • Type of data
        • The algorithms are written to compare integer data.  If you are comparing some other type of data you will need to change the comparison (if statement) and the temporary variable.
          • If you are comparing double data - no changes are needed.
          • If you are comparing an object - you will need to make changes.
            • If you are comparing string values you will need to use the .compareTo() method.
      • How do you get to the data?
        • If you are comparing an instance variable of an object, you need to get to that instance variable.
          • You will need to get the object at position i and position i+1, perhaps putting these objects into a temporary object variable.
          • Then you will to call the method(s) to retrieve the instance variable.
          • You will then be able to compare values.
      Reflection Paper
      • It's time to start working on your reflection paper, compiling your journal entries into an actual paper with an opening paragraph, middle section with your reflections, and a close paragraph.
      Lab 5
      •  Although you have a couple of weeks to complete this lab, it's never a good idea to wait until the last minute.  Read through the instructions. Make sure you have a clear understanding of what is needed.