Question: 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 HashMap<Video,Record>.
* 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 = new HashMap();
InventorySet(){}
/**
* Return the number of Records.
*/
public int size(){
return 0;
// TODO
}
/**
* Return a copy of the record for a given Video; if not present, return null.
*/
public Record get(Video 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 addNumOwned(Video 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(Video 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(Video video){
// TODO
}
/**
* Remove all records from the inventory.
* @postcondition size()==0
*/
public void clear(){
_data.clear();
}
/**
* Return the contents of the inventory as a string.
*/
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();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!