CS 4448 - Spring 1998
Object-Oriented Programming and Design
Homework #2

Due on Thursday, January 29 at the start of class.

This assignment must be typed (handwritten homework will not be graded)
Print out Part 1 and Part 2 with some example tests that you ran on Part2. Some tests means each function is demonstrated but I do not want pages of tests. Also email me the file for part 2 in the format that I can file in.

Part 1 - AJG class

  1. Use the file hw2.example.st located here or on the ugrad computers in directory (~griff/CS4448 or /nfs/home/cia/griff/CS4448) and file it in.
  2. What category is my class in?
  3. What is the name of my new class?
  4. What class is it derived from?
  5. How many constructors does this class have and what are they?
  6. What is the instance variable and what methods effect it?
  7. Now it is time to use the class. So open a Workspace and do the following commands in order and make sure to answer the questions in order as well. Note: If you get an error then you are not using the classes correctly so keep working on it. Also, use print-it (not do-it) so we can see the results. Note: you will be copying your workspace when you are done into your homework.

      Create a new instance with the instance variable uninitialized and store the class in variable "temp".
    1. Before doing anything else inspect the variable "temp" and write down what is in "location" and what is the class of "location" which you get by inspecting it?
      Change the location in "temp" to the value 5@1
    2. Now look at "temp", what class is "location" an instance of and what instance variable does it have?
      Create a new instance where location gets initialized at instantiation to 3. Store the class to "temp2".
    3. So in "temp2" what class does "location" belong to?
      Try to add the "location" from "temp2" to the one in "temp".
    4. Why does it fail?
      Add the "location" from "temp" to the one in "temp2" and store the result into "temp3".
    5. What class is "temp3" an instance of?
    6. Explain the numerical result of the math operation, how was the math performed to get that result? Why did it work this time? Give the details of the process which will require you to check out the class in the browser.
      Finally add "temp3" to 9 and the "location" of "temp" and store the result into the existing "temp2" object "location" variable.
    7. Paste your workspace for this problem here
  8. Find the example of a polymorphic interface in this class and give two ways they are different? I do not want you to discuss class to base class polymorphic interfaces, stay within the new code that was added.

Part 2 - Create your own class

Remember that in Squeak categories for class and methods are just for organization and have no effects. Try to place the methods in nice categories like you see in the other classes.
  • Create a new category called HW#2 and place the new object class called Triple in that category. The Triple class should have base class Point. Add the instance variable z to your new class and methods z and z: . Also add instance method "setX: setY: setZ:" and class method "x: y: z:". You will need to implement printOn: and storeOn: in the class so the object can display itself properly. Implement a way so that Points can be converted to Triples via the @ method but Triples should then undefine the @ method. Implement the methods for operator + and -. + and - needs to work for Triple + Triple, Triple + Point, and Triple + Number. DO NOT implement the other direction (i.e. Number + Triple) since this is the deadly problem I mentioned in class. Do min:, max:, and rounded so they perform similar tasks that you can SEE in the Point class. Add the conversions asTriple so it is understood by the Number class, Point class, and Triple class. Add asPoint to the Triple class isnce this will help in your implementation (hint + and -). Note: reuse code of the parent classes. Bonus if you can write a storeOn: method that can be filed in and generate an object.

    Just to list all the methods to add:
    Number class - asTriple
    Point class - @, asTriple
    Triple class - class method x: y: z:, setX: setY: setZ:, printOn:, storeOn:, z, z:, min:, max:, rounded, @, asPoint, asTriple, +, -

    One final important note. You can see how inheritance works since printOn:, min:, @, and other methods will work even if you don't do them in the Triple class but they don't return the desired result.

    Bonus:

  • Hint: The Internet and search engines have made trivia easy.
  • Name the book and author that inspired the movie, "The Adventures of Buckaroo Banzai Across the 8th Dimension ?"
  • Who played Doctor Emilio Lizardo/Lord John Whorfin?
  • Name 2 movies for which this actor received Academy Awards nominations?
  • Finally lets play the closest path connecting names game which I explained in class. Give me the shortest path between Quentin Tarantino and Jack Nicholson?
    Adam Jonathan Griff, computer@griffmonster.com
    Copyright © University of Colorado. All rights reserved.
    Revised: January 27, 1998