Question
In HW 5, we will begin to implement a simple inventory control system for a video shop. The starter code includes the following classes: InventorySet
In HW 5, we will begin to implement a simple inventory control system for a video shop. The starter code includes the following classes:
- InventorySet : An Inventory implemented using a HashMap
. - Keys are Videos; Values are Records.
- Record : Utility class for Inventory.
- Fields are mutable and package-private.
- Does not override equals or hashCode.
- VideoObj : Immutable data class for Video objects.
- Comprises a triple: title, year, director.
and the following tests:
- InventorySetTest : Unit tests for InventorySet.
- RecordTest : Unit tests for Record.
- VideoObjTest : Unit tests for VideoObj.
- testHashCode : assumes that the recipe outlined in Bloch Chapter 3 was used for hashCode
- Complete the basic classes (marked by TODOs) an immutable data class and a collection.
- First, write VideoObj and VideoObjTest. Get all tests to pass.
- Then, write InventorySet and InventorySetTest. Get all tests to pass.
- There are 22 TODOs in HW 5.
- Partial Javadoc documentation (i.e. function description) is provided. Complete proper Javadoc documentation for all public functionality in InventorySet, Record, and VideoObj classes.
- See (Java) Documentation & Style Standards in the Useful Information module.
- Generate Javadoc comments for all classes and unit tests (include private, package-private, protected, and public visibilities). Below is sample code with TODO
Invariant: _data != null
Postcondition: size() == 0
Invariant: non-null, no leading or final spaces, not empty private final String title; /**
Invariant: greater than 1800, less than 5000
*/ private final int year; /**Invariant: non-null, no leading or final spaces, not empty private final String director; ** /* * Initialize all object attributes. * Title and director are "trimmed" to remove leading and final space. * @throws IllegalArgumentException if any object invariant is violated. */ VideoObj(String title, int year, String director) { // TODO: implement VideoObj constructor this.title = null; this.year = 0; this.director = null; } * /** Return the value of the attribute. */ public String director() { // TODO: implement director method return "director"; } /** * Return the value of the attribute. */ public String title() { // TODO: implement title method return "title"; * Return the value of the attribute. */ public int year() { // TODO: implement year method return -1; } * Compare the attributes of this object with those of thatObject. @Override public boolean equals(Object thatObject) { // TODO: implement equals method return false; } /** * Return a hash code value for this object using the algorithm from Bloch: * fields are added in the following order: title, year, director. */ @Override public int hashcode() { // TODO: implement hashCode method return -1; } Compares the attributes of this object with those of thatObject, in. @Override public int compareTo(VideoObj thatObject) { // TODO: implement compareTo method return -1; } /** * Return a string representation of the object in the following format: * "title (year) : director"
. */ @Override public String toString() { // TODO: implement toString method return "El Mariachi (1996) Rodriguez". @Test public void testConstructorExceptionDirector() { // TODO: complete testConstructorExceptionDirector test } @Test public void testHashcode() { assertEquals (-1869722747, new VideoObj("None", 2009, "Zebra").hashCode()); assertEquals (2057189520, new VideoObj("Blah", 1954, "Cante").hashcode()); } @Test public void testEquals() { // TODO: complete testEquals test } @Test public void testCompareTo() { // TODO: complete testCompareTo test } @Test public void testToString() { String s = new VideoObj("A", 2000, "B").toString(); assertEquals( "A (2000) : B", s ); s = new VideoObj("A", 2000, B ").toString(); assertEquals( "A (2000) : B", s); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started