CMSI 281
Homework #1

Read [Gray], Chapters 0, 1, and Chapter 2 up through 2.2 only. Consider the "Checkpoint" questions as part of your reading assignment: answer them but don't turn in your answers. Also read [Bloch], items 1-5, 7-9, 13, and 31.

Submit answers to the following problems, in a nicely typeset pdf file:

  1. Give a UML class diagram for a part of an HR database that keeps track of employees and their managers (who are also employees), the departments they work in, and the projects they work on. Employees have a name, birthday, salary, and zero or one mananger. Employees can belong to one or two departments and can work on any number of projects, including zero. Projects have a budget and are run by a single department. In your diagram, show fields but not operations, and show all cardinalities. Pay attention to generalization, composition and aggregation.
  2. Write an immutable 2-D Point class, with coordinates of type double. Override equals, hashCode, and toString.
  3. Write a unit test for the Point class, using JUnit 4.x.
  4. Write a mutable 2-D line class. A line is described with a point and a direction (the number of radians counterclockwise from the positive x axis). Provide getters for the point and direction, but set them by "moving" and "rotating" the line. Include a method to return the distance between a point and a line, and a method to determine whether two lines are parallel. Override toString.
  5. Write a unit test for the Line class, using JUnit 4.x.
  6. Write a class for playing cards. Each card has a rank (ace...king), and a suit (spades, hearts, diamonds, clubs). The Card class should have nested static enum classes called Rank and Suit. Override toString to produce values such as "4D", "10H", "JS", "KC", "AD", "6H", "QD", etc., and include a static factory method to return a card given such a string. Override equals and hashCode, unless you are able to guarantee exactly one instance of each possible card.

You will be creating a document that contains numbered solutions to the problems, using LaTeX, OpenOffice, Word, or other document preparation system. If a particular problem asks for source code, you may embed the source in place in the document, or give the answer as "See <filename>" and place the source code at the end of the document. Compose the pdf with the solutions to each problem, numbered, and in order. You must submit a hard copy of the pdf and the source code in one packet of stapled together 8.5" × 11" sheets of paper. You must also make available source code in electronic form, either by emailing me a zip file containing the sources, or by providing me readonly access to a cvs or svn repository, where I can check out code by date.

Your sources should be organized as follows:

homework
  cmsi281
    src
      main
        docs
          hw1.tex (or .odt or .doc or ...)
          <diagram source files>, if any
          <images>, if any
        java
          edu
            lmu
              cs
                geometry
                  Point.java
                  Line.java
                games
                  Card.java (contains inner classes Suit and Rank)
      test
        java
          edu
            lmu
              cs
                geometry
                  PointTest.java (JUnit test case)
                  LineTest.java (JUnit test case)
                games
                  CardTest.java (JUnit test case)
Notes