We first review the Design Recipe and then show how we can express our programs in Java instead of Racket. We cover the basic syntax for classes, fields, and methods, as well as how to create new object instances.

We introduce a simple memory model for Java and walk through an example. We conclude the module with an introduction to Javadoc, Java's documentation tool, as well as testing with JUnit.

  1. List three Java primitive types.
  2. Write an example of a reference type.
  3. Given a list of Java values, mark the values that are reference types.
  4. Given a list of Java values, mark the values that are primitive types.
  5. Given a Java class use it to create one object instance.
  6. Use Javadoc in your comments to write purpose statements for Java methods.
  7. Given a set of Java classes with Javadoc annotations, build the html output.
  8. Given a data definition for a Racket Structure, write the corresponding Java class.
  9. Given a data definition of a one-level nested structure, write the corresponding Java class.
  10. Given a Java class, draw the corresponding UML class diagram.
  11. Given a UML class diagram, translate it into Java classes.
  12. Write the names of the two types of memory used by the JVM.
  13. Explain the difference between the equals method and == when used with reference types.
  14. Given a set of Java classes, add methods to define equality.
  15. Given a Java class with methods, write JUnit tests to verify the correctness of the methods.

  • DUE DATE: January 20th @ 12:00pm

Resources

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

Problem 1

All your code for this problem must be inside a the java package edu.neu.ccs.cs5004.seattle.assignment1.problem1.

A friend is trying to create a program to keep track of their library of books. He has started designing the program and after a first iteration your friend has created the following UML class diagram.

Books Class Diagram

Your friend asked you to create the code based on his Class Diagram to implement the following:

  • Book
    1. implement the toString() method for Book and provided the following as an example: for the book "The Unbearable Lightness of Being", written by Milan Kundera published in 1984 with ISBN 9780061148521, it should output "The Unbearable Lightness of Being", Milan Kundera (1984), ISBN:978-0061148521
    2. implement the equals() and hashCode() methods such that two Books are considered the same if and only if they have the same title, author, year and ISBN. Ensure that your implementation satisfies the contracts for both methods equals(Object): boolean and hashCode(): int
  • Author
    1. implement the toString() method for Author so that it returns in order the first, middle and second name separated by spaces. In the case that an author does not have a middle name, i.e., it is set to "" return a string composed of the first and second name separated by one space.
    2. implement the equals() and hashCode() methods such that two Authors are considered the same if and only if they have the same first, middle and second names. Ensure that your implementation satisfies the contracts for both methods equals(Object): boolean and hashCode(): int
  • Isbn
    1. implement the toString() method for Isbn so that it returns in order the prefix followed by a hyphen, followed by group, publicationElement, registrationElement and checkDigit.
    2. implement the equals() and hashCode() methods such that two Isbns are considered the same if and only if they have the same prefix, group, publicationElement, registrationElement, and checkDigit. Ensure that your implementation satisfies the contracts for both methods equals(Object): boolean and hashCode(): int
  • Year
    1. implement the toString() method for Year so that it returns a string representation of the value val inside Year.
    2. implement the equals() and hashCode() methods such that two Years are considered the same if and only if they have the same Integer value. Ensure that your implementation satisfies the contracts for both methods equals(Object): boolean and hashCode(): int
  • Title
    1. implement the toString() method for Title so that it returns a string representation of the value val inside Title.
    2. implement the equals() and hashCode() methods such that two Titles are considered the same if and only if they have the same String value. Ensure that your implementation satisfies the contracts for both methods equals(Object): boolean and hashCode(): int

Problem 2

All Java source code that is part of your solution to this problem must reside inside a java package with the name edu.neu.ccs.cs5004.seattle.assignment1.problem2

You have been tasked to create the program to print boarding passes at airports. The boarding pass contains the following information:

  • The passenger's name. A boarding pass has one and only one passenger. The passenger has a first and last name and some might also have a middle name.
  • The name of your destination. This is typically the name of a city.
  • The name of your departure. This is typically the name of the city.
  • The time of departure. Time is hours and minutes only. The hours are in 24 hour format; 0 to 23 where 0 is midnight and 23 is 11pm. Time should be displayed with hours first, then a colon : and then minutes
  • The date of departure. This is the day, month and year, e.g., 01/22/2015. The example is also the way that the date appears on the boarding pass
  • The gate from which you are departing. Gates have a composite name made up of a capital letter and a number, e.g., A87
  • The passenger's boarding group. The boarding group is typically a number, e.g., 4.
  • The airline with which the passenger is travelling, e.g., British Airways
  • The flight number. The flight number is also a composed from two pieces of information, the airlines acronym and a number, e.g., BA8787
  1. Provide Java code for your design. For each class that you create ensure that you have an appropriate implementation of toString(), equals() and hashCode()
  2. The airport administrator forgot to mention that the boarding pass should also include the seat number of the passenger. A seat number consists of a letter and a number, e.g. A4. This is also how your code should display the seat number; a character and a number with no space between the two.

SUMMARY OF ASSIGNMENT

Item Points
Code builds 2
Tests run with no errors/failures 5
Javadoc builds with no errors/warnings 5
Problem 1 81
Problem 2 156
GRAND TOTAL: 249