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.
- List three Java primitive types.
- Write an example of a reference type.
- Given a list of Java values, mark the values that are reference types.
- Given a list of Java values, mark the values that are primitive types.
- Given a Java class use it to create one object instance.
- Use Javadoc in your comments to write purpose statements for Java methods.
- Given a set of Java classes with Javadoc annotations, build the html output.
- Given a data definition for a Racket Structure, write the corresponding Java class.
- Given a data definition of a one-level nested structure, write the corresponding Java class.
- Given a Java class, draw the corresponding UML class diagram.
- Given a UML class diagram, translate it into Java classes.
- Write the names of the two types of memory used by the JVM.
- Explain the difference between the equals method and == when used with reference types.
- Given a set of Java classes, add methods to define equality.
- 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.
Your friend asked you to create the code based on his Class Diagram to implement the following:
- Book
-
implement the
toString()
method forBook
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
-
implement the
equals()
andhashCode()
methods such that two Books are considered the same if and only if they have the sametitle
,author
,year
andISBN
. Ensure that your implementation satisfies the contracts for both methods equals(Object): boolean and hashCode(): int
-
implement the
- Author
- implement the
toString()
method forAuthor
so that it returns in order thefirst
,middle
andsecond
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 thefirst
andsecond
name separated by one space. -
implement the
equals()
andhashCode()
methods such that twoAuthor
s are considered the same if and only if they have the samefirst
,middle
andsecond
names. Ensure that your implementation satisfies the contracts for both methods equals(Object): boolean and hashCode(): int
- implement the
-
Isbn
-
implement the
toString()
method forIsbn
so that it returns in order theprefix
followed by a hyphen, followed bygroup
,publicationElement
,registrationElement
andcheckDigit
. -
implement the
equals()
andhashCode()
methods such that twoIsbn
s are considered the same if and only if they have the sameprefix
,group
,publicationElement
,registrationElement
, andcheckDigit
. Ensure that your implementation satisfies the contracts for both methods equals(Object): boolean and hashCode(): int
-
implement the
-
Year
-
implement the
toString()
method forYear
so that it returns a string representation of the valueval
inside Year. -
implement the
equals()
andhashCode()
methods such that twoYear
s are considered the same if and only if they have the sameInteger
value. Ensure that your implementation satisfies the contracts for both methods equals(Object): boolean and hashCode(): int
-
implement the
-
Title
-
implement the
toString()
method forTitle
so that it returns a string representation of the valueval
inside Title. -
implement the
equals()
andhashCode()
methods such that twoTitle
s are considered the same if and only if they have the sameString
value. Ensure that your implementation satisfies the contracts for both methods equals(Object): boolean and hashCode(): int
-
implement the
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
-
Provide Java code for your design. For each class that you create ensure that
you have an appropriate implementation of
toString()
,equals()
andhashCode()
- 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 |