Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.util.Map; import java.util.HashMap; import java.util.Collection; / * * * An Inventory implemented using a HashMap < Video,Record > . * Keys are Videos; Values
import java.util.Map; import java.util.HashMap; import java.util.Collection; An Inventory implemented using a HashMapVideo,Record Keys are Videos; Values are Records. @objecttype Mutable Collection of Records @objectinvariant Every key and value in the map is nonnull. @objectinvariant Each value r is stored under key rvideo. final class InventorySet @invariant data null private final Map data new HashMap; InventorySet Return the number of Records. public int size return ; TODO Return a copy of the record for a given Video; if not present, return null. public Record getVideo v return null; TODO Return a copy of the records as a collection. Neither the underlying collection, nor the actual records are returned. public Collection toCollection 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 zero, 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, change is zero, if attempting to remove more copies than are owned, or if attempting to remove copies that are checked out. @postcondition changes the record for the video public void addNumOwnedVideo 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 checkOutVideo video TODO Check in a video. @param video the video to be checked in @throws IllegalArgumentException if video has no record or numOut nonpositive. @postcondition changes the record for the video public void checkInVideo video TODO Remove all records from the inventory. @postcondition size public void clear data.clear; Return the contents of the inventory as a string. public String toString StringBuilder buffer new StringBuilder; buffer.appendDatabase: ; for Record r : data.values buffer.append; buffer.appendr; buffer.append ; return buffer.toString;
import java.util.Map;
import java.util.HashMap;
import java.util.Collection;
An Inventory implemented using a HashMapVideo,Record
Keys are Videos; Values are Records.
@objecttype Mutable Collection of Records
@objectinvariant
Every key and value in the map is nonnull.
@objectinvariant
Each value r is stored under key rvideo.
final class InventorySet
@invariant data null
private final Map data new HashMap;
InventorySet
Return the number of Records.
public int size
return ;
TODO
Return a copy of the record for a given Video; if not present, return null.
public Record getVideo v
return null;
TODO
Return a copy of the records as a collection.
Neither the underlying collection, nor the actual records are returned.
public Collection toCollection
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 zero,
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, change is zero,
if attempting to remove more copies than are owned, or if
attempting to remove copies that are checked out.
@postcondition changes the record for the video
public void addNumOwnedVideo 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 checkOutVideo video
TODO
Check in a video.
@param video the video to be checked in
@throws IllegalArgumentException if video has no record or numOut
nonpositive.
@postcondition changes the record for the video
public void checkInVideo video
TODO
Remove all records from the inventory.
@postcondition size
public void clear
data.clear;
Return the contents of the inventory as a string.
public String toString
StringBuilder buffer new StringBuilder;
buffer.appendDatabase:
;
for Record r : data.values
buffer.append;
buffer.appendr;
buffer.append
;
return buffer.toString;
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