Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

FINISH ALL TODO import java.util.Map; import java.util.HashMap; import java.util.Collection; import java.util.ArrayList; import java.util.Iterator; // TODO: complete the methods /** * An Inventory implemented using a

FINISH ALL TODO

import java.util.Map; import java.util.HashMap; import java.util.Collection; import java.util.ArrayList; import java.util.Iterator;

// TODO: complete the methods /** * An Inventory implemented using a HashMap. * Keys are Videos; Values are Records. * * @objecttype Mutable Collection of Records * @objectinvariant * Every key and value in the map is non-null. * @objectinvariant * Each value r is stored under key r.video. */ final class InventorySet { /** @invariant _data != null */ private final Map _data;

InventorySet() { _data = new HashMap(); }

/** * Return the number of Records. */ public int size() { // TODO return 0; }

/** * Return a copy of the record for a given Video. */ public Record get(VideoObj v) { // TODO return null; }

/** * Return a copy of the records as a collection. * Neither the underlying collection, nor the actual records are returned. */ public Collection toCollection() { // Recall that an ArrayList is a Collection. // TODO return null; }

/** * Add or remove copies of a video from the inventory. * If a video record is not already present (and change is * positive), a record is created. * If a record is already present, numOwned is * modified using change. * If change brings the number of copies to be less * than one, the record is removed from the inventory. * @param video the video to be added. * @param change the number of copies to add (or remove if negative). * @throws IllegalArgumentException if video null or change is zero * @postcondition changes the record for the video */ public void addNumOwned(VideoObj video, int change) { // TODO }

/** * Check out a video. * @param video the video to be checked out. * @throws IllegalArgumentException if video has no record or numOut * equals numOwned. * @postcondition changes the record for the video */ public void checkOut(VideoObj video) { // TODO } /** * Check in a video. * @param video the video to be checked in. * @throws IllegalArgumentException if video has no record or numOut * non-positive. * @postcondition changes the record for the video */ public void checkIn(VideoObj video) { // TODO } /** * Remove all records from the inventory. * @postcondition size() == 0 */ public void clear() { // TODO }

/** * Return the contents of the inventory as a string. */ public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("Database: "); for (Record r : _data.values()) { buffer.append(" "); buffer.append(r); buffer.append(" "); } return buffer.toString(); } }

import junit.framework.Assert; import junit.framework.TestCase; import java.util.Iterator; import java.util.Set; import java.util.HashSet;

// TODO: complete the tests public class InventoryTEST extends TestCase { public InventoryTEST(String name) { super(name); }

// TODO public void testSize() { // TODO }

public void testAddNumOwned() { // TODO }

public void testCheckOutCheckIn() { // TODO }

public void testClear() { // TODO }

public void testGet() { // TODO }

public void testToCollection() { // 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. // TODO } }

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

Beginning VB.NET Databases

Authors: Thearon Willis

1st Edition

1594864217, 978-1594864216

More Books

Students also viewed these Databases questions