Homework 2

Homework 2 consists of answering the questions below and submitting the assignment to me via e-mail using the guidelines presented on slide 13 of lecture 1 dealing with zip/tar archives. This homework is worth 75 points (5 points for each UML question, 10 points for the short answer question, 20 points each on the programming questions).

  1. Draw a UML class diagram that models the following statements: “A is a subclass of B. A implements interface C which is used by D to access A. B is associated with 5 E's.”
  2. Draw a UML class diagram that models the following statements: “CargoPlane aggregates zero or more Pallets. Each Pallet aggregates zero or more Boxes; CargoPlane is composed of one or more Parts. Some important Parts include four JetEngines, two Wings and four Wheels.”
  3. Draw a UML class diagram that models the following statements: “A University is composed of one or more Units, such as Colleges and Schools. Each Unit contains faculty, students and staff and maintain an address book that maintains contact information for each person in that unit. A person can be located in the address book by supplying their last name or their university id.”
  4. Answer the following question about the class diagram you created in question 1: “Can D access an instance of B via C's interface? Explain.”
  5. In Lecture 4, we reviewed an example program called Test that created and manipulated a GroceryList. Internally, the GroceryList made use of a LinkedList via delegation. Examine the sample code closely and then create a UML class diagram that models the classes used in this program and their relationship. Do not worry about modeling the fact that the LinkedList was configured to contain only String objects. Your diagram does not need to include the String class.
  6. Imagine we have a system that has a class called Shape and subclasses Square, Circle, and Triangle each developed by a different software engineer. The system uses these classes to display randomly generated displays that balance various constraints concerning the area and perimeter of each individual shape along with the total area and total perimeter of all shapes on the screen. (An example of such a constraint might be that the total area of all shapes must always be twice as large as the total perimeters.) The engineer responsible for the Square class is feeling upset that they didn't receive the employee of the month award for a third month in a row and decides to “act out” by implementing the getArea() method of Square by having it return the perimeter of the Square instead. What design heuristic presented in Lecture 2 about classes has this engineer violated and what repercusions will it have in the overall system.
  7. Implement a simple program (on the order of the sample programs presented in lecture so far) that implements a basic inventory system for a video rental store that has various categories of movies. Each category has a different rental price associated with it; that price indicates how much it costs per day to rent the video. The purpose of this simple program is to generate a report that identifies how many movies of each category the store contains and how much it would cost to rent all of those movies for two days each.
  8. Implement a simple program that has classes A, B, and C that honors the following constraints and performs the following actions.

    Constraints

    • Each A, B, and C have an id.
    • A aggregates two to four B's.
    • B's aggregate three or more C's.
    • A and B can generate a report that indicates how many things they contain. For instance A's report might say, “A[1] contains B[1] and B[2]. B[1] contains C[1], C[2] and C[3]. B[2] contains C[4], C[5], and C[6].” Note: Your report does not have to look exactly like this but it should show the transitive containment relationships.

    Actions

    1. Create a B
    2. Ask B to generate a report.
    3. Create two C's and add them to B.
    4. Create another B.
    5. Use the two B's to create an A.
    6. Have A generate a report.
    7. Create three more B's and add them to A.
    8. If your program is still running, have A generate a report. If your program stops running in the previous step, it should generate an error message before it terminates.

For the programming problems, you may use any of the following object-oriented programming languages including Java, C++, C#, python, ruby or Javascript. If you'd like to use some other language, please ask Prof. Anderson first. Be sure to include a README file that describes your program, how to compile it (if needed) and how to execute it.

Your archive will contain a PDF file with the answers for questions 1-6 and two directories containing the code for problems 7 and 8.

Due Dates: Homework 2 is due by 11:59 PM on Wednesday, January 26, 2011. Any homework submitted after that time but by 11:59 PM on Wednesday, February 2, 2011 will be graded but will receive a 15% penalty. After that, submissions of Homework 2 will be ignored.

You are encouraged to work in teams on this assignment; it is not required just encouraged. Get started soon!

© Kenneth M. Anderson, 2011