In this module we continue to explore how different kinds of data definitions are captured into Java classes by introducing interfaces and inheritance. We also introduce the notion of equality between reference types and how Java allows programmers to define equality for their classes.

We further extend our memory model for Java programs to accommodate for inheritance. We conclude this module with the introduction of Java packages and UML sequence diagrams.

  1. Given a set of Java class definitions, list all subtypes for each class.
  2. Given a set of Java class definitions, list all supertypes for each class.
  3. Given the data definition for an itemization, write the corresponding Java classes.
  4. Given a recursive data definition, write the corresponding Java classes.
  5. Given a mixed data definition, write the corresponding Java classes.
  6. Given a data definition for Scheme lists, write the corresponding Java classes.
  7. Given a UML class diagram for immutable lists, implement list processing methods.
  8. Given a Java class with a main method, draw a diagram to show the state of the JVM's memory.
  9. Given an Abstract Data Type specification draw the UML class diagram for your design.
  10. Given a specification for an Abstract Data Type (ADT), translate into appropriate Java classes.
  11. Given a set of Java classes, add methods to define equality.
  12. Given a Java class with methods, write JUnit tests to verify the correctness of the methods.
  13. Given a set of Java classes, use the Java package system to group them into a package.
  14. Use Javadoc in your comments to write purpose statements for Java methods.
  15. Given an implementation of a Java method, draw the corresponding sequence diagram.
  16. Given a UML sequence diagram, translate it into Java methods.

  • DUE DATE: Jan 24th @11:59pm

Resources

Here are some online resource that you might find usefull while tackling this assignment.

Submission Requirements

Your repository should contain the following files

  • One .java file per Java class
  • One .java file per Java test class
  • One pdf or image file for each UML Class Diagram that you create

You repository should not contain

  • Any .class files
  • Any .html files
  • Any IntelliJ specific files

Grading Criteria

  1. Code compiles with no errors.
  2. All classes come with tests.
  3. All tests run with no failures.
  4. All code comes with valid Javadoc comments.
  5. Javadoc generation has no errors or warnings.
  6. All classes have equals,hashCode, toString implementations.
  7. Fields are only set inside constructor methods.
  8. Properly abstract common code.
  9. No void methods.
  10. No use of casting (except for equals method).
  11. No use of primitive types (except for equals method).
  12. No use of null (except for equals method).

Problem 1

A Professor from another department asked for your help in order to write a program that will manipulate technical publications.

A publication can be one of

  • Conference. These are paper that have been published at a conference. We would like to capture the following information for conference publications.
    • Title: this is the paper's title.
    • Author: the author's name. There can only be one author.
    • Conference Name: the name of the conference.
    • Location: the location of the conference, typically a city and country, e.g. "Seattle, USA"
    • Month: the first three letters of the month, e.g., Oct
    • Year: the 4-digit calendar year.
  • Journal. These are papers that have been published to a Journal. We would like to capture the following information for journal publications.
    • Title: this is the paper's title.
    • Author: the author's name. There can only be one author.
    • Journal Name: the name of the Journal.
    • Issue: the issue number of the Journal, typically a number, e.g., 26
    • Month: the first three letters of the month, e.g., Oct
    • Year: the 4-digit calendar year.
  • Technical Report. These are papers that have been published as technical reports. We would like to capture the following information for technical report publications.
    • Title: this is the paper's title.
    • Author: the author's name. There can only be one author.
    • TR-ID: an identifier for this technical report, typically a number, e.g., 3425
    • Institution: the name of the institution publishing the technical report.
    • Year: the 4-digit calendar year.

Author names come in two flavours. An author's name is one of

  • Full Name: consists of the author's first and last name.
  • Official Name: consists of the author's first, middle, last names and title.
  1. Design Java classes to capture the above requirements including implementations for toString(), hashCode() and equals(Object o).
  2. The professor would like to add a reference id to each publication. A reference id is a string, e.g., "FFJ95" that we can set on a publication. Extend your design to accommodate for reference ids.
  3. Provide your UML Class Diagram for your design at this point.
  4. The professor would also like to add book chapters as another type of publication. A book chapter has the following information associated with it
    • Chapter Title: this is the chapter's title as a string
    • Author: the author's name. There can only be one author
    • Book Title: the book's title as a string.
    • Month: the month the book was published.
    • Year: the year the book was published.
    • Editor: the editor's name. There can only be on editor.
    Extend your design and your code to accommodate for book chapters. You do not need to update your UML Class diagram for this part of the question, only your code.
  5. The professor would also like the ability to take an existing Technical Report and turn it into a Journal. Your program should provide a method defined on Technical reports that will accept
    • the Journal's name
    • the Journal's issue
    • the month
    • and the year
    and return a new Journal that has the new Journal name, issue, month and year, but all other values are copied from the Technical Report. For example, if I have a Technical Report with the following information
    • Title: "The art of lies"
    • Author: "John Steward"
    • TR-ID: 1224
    • Institution: "Institute of Human Behavior"
    • Year: 1999
    and provide the following Journal information
    • Name: "Science of Lies"
    • Issue: 33
    • Month: Jul
    • Year: 2001
    We should get back a Journal with the following information
    • Title: "The art of lies"
    • Author: "John Steward"
    • Journal Name: "Science of Lies"
    • Issue: 33
    • Month: Jul
    • Year: 2001
  6. Provied the final UML Class Diagram for your final solution to this problem.

Problem 2

We are asked to implement a simplified version of the game rock-paper-scissors.

The game consists of two players. The players select one of three states

  1. Rock,
  2. Paper, or,
  3. Scissors

The players make their selection simultaneously. The winner is decided based on the following rules

  • Rock beats Scissors
  • Scissors beats Paper
  • Paper beats Rock
  1. Design a Java program to represents the three possible states of the game
  2. Include in your design a method shared by all states that consumes another state and returns a boolean indicating a win according to the rules above by returning true or a loss by returning false. For example if we have an object that represents the state Paper and we pass to that object another object that represents Rock, the we should return true since the object that received the challenge won based on the game rules.
    NOTE: You can solve this problem without casting or the use of getClass(). For this problem only we will allow solutions that use casting or getClass().

Problem 3

We are trying to build a prototype for a video game. The game designers have an idea and would like you to build a program to test their idea out.

The game consists of a map that we are going to represent as a grid and we are going to use Cartesian coordinates to designate position, e.g., (x,y). The game has Pieces. A Piece is one of

  • Civilian
  • Soldier

A Civilian is one of

  • Farmer
  • Engineer

A Soldier is one of

  • Sniper
  • Marine

The designers provided the following properties

  1. All pieces must keep track of their current position as a Cartesian coordinate
  2. All pieces must be able to move given a target location (another Cartesian coordinate). Pieces however move at different speeds towards their target.
    • Civilians move at most 1 unit in the x or y or both directions. If we have a civilian at location (2,3) and the civilian is given a target of (10,10) then the civilian can move 1 unit in the x-direction and one unit in the y direction. Another example, if the civilian is at location (3,6) and the target given is location (3,9) the civilian can move to (3,7). If the target location and the location of the civilian is the same then the civilian does not move at all.
    • Soldiers have the same restrictions but soldiers can move at most 2 units in the x or y or both directions.
  3. Civilians generate wealth. Each civilian must keep track of its wealth. Wealth is basically a number. We should be able to increase a civilian's wealth by passing a number to add to the current wealth of a civilian. We should be able to decrease a civilian's wealth by passing a number to remove from the current wealth of a civilian.
  4. Soldiers keep track of their stamina. Each soldier must keep track of its stamina. Stamina is basically a number. We should be able to increase a soldier's stamina by passing a number to add to the current stamina of a soldier. We should be able to decrease a soldier's stamina by passing a number to remove from the current stamina of a soldier.

Design a Java program to capture the information and properties described by the game designers. Provide your final UML Class Diagram as well as your code.