Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 TODOimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
@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 data = new HashMap /** * Default constructor. */ InventorySet() { } * /** Return the number of Records. */ public int size() { // TODO: implement size method return 0; } * /** Return a copy of the record for a given Video; if not present, returi */ public Record get(VideoObj v) { // TODO: implement get method return null; } * Return a copy of the records as a collection.. public Collection toCollection() { // TODO: implement toCollection method // Recall that an ArrayList is a collection. return null; } * Add or remove copies of a video from the inventory.. public void addNumOwned (VideoObj video, int change) { // TODO: implement addNumOwned method } * Check out a video. Solidacob dan * Add or remove copies of a video from the inventory.. public void addNumOwned (VideoObj video, int change) { // TODO: implement addNumOwned method } * Check out a video.. public void checkout(Videoobj video) { // TODO: implement checkout method } * Check in a video.. public void check In (VideoObj video) { // TODO: implement checkIn method } ** * Remove all records from the inventory. *

Postcondition: size() == 0

*/ public void clear() { // TODO: implement clear method } * Return the contents of the inventory as a string.. @Override public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append("Database: "); for (Record r : data.values()) { buffer.append(" "); buffer.append(r); buffer.append(" "); } return buffer.toString(); } final class VideoObj implements Comparable { /**

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

What is Constitution, Political System and Public Policy? In India

Answered: 1 week ago

Question

What is Environment and Ecology? Explain with examples

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago