Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please finish the todo parts and explian import java.util.Map; import java.util.HashMap; import java.util.Collection; / * * * An Inventory implemented using a HashMap. * Keys

please finish the todo parts and explian
import java.util.Map;
import java.util.HashMap;
import java.util.Collection;
/**
* 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 = 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();
}
}
p

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

Students also viewed these Databases questions

Question

What is one of the skills required for independent learning?Explain

Answered: 1 week ago