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





@Test public void test Checkout CheckIn() { // TODO: complete testcheckOutcheckIn test } @Test public void testClear() { // TODO: complete testclear test } @Test public void testGet() { // TODO: complete testGet test // Get should return a COPY of the records, not the records themselves. } @Test public void testToCollection() { // TODO: complete testToCollection test // Be sure to test that changing records in the returned // collection does not change the original records in the // inventory. ToCollection should return a COPY of the records, // not the records themselves. } final class InventorySet { /**
Invariant: _data != null
*/ private final Map Postcondition: Invariant: non-null, no leading or final spaces, not empty private final String title; /** Invariant: greater than 1800, less than 5000 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: * size() == 0"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
Get step-by-step solutions from verified subject matter experts
