954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

video inventory

could some one explain the code below

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


final class InventorySet {
  /** @invariant <code>_data != null</code> */
  private final Map<VideoObj,Record> _data = new HashMap<VideoObj,Record>();

  InventorySet() { }

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

  
  public Record get(VideoObj v) {
    // fill in the code

    return null;
  }


  public Collection<Record> 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, <code>numOwned</code> is
   * modified using <code>change</code>.
   * If <code>change</code> 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(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 <code>size() == 0</code>
   */
  public void clear() {
    // fill in the code
  }

  
  public String toString() {
    StringBuilder buffer = new StringBuilder();
    buffer.append("Database:\n");
    for (Record r : _data.values()) {
      buffer.append("  ");
      buffer.append(r);
      buffer.append("\n");
    }
    return buffer.toString();
  }
}

thanks in advance

CodeJava1
Newbie Poster
4 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

what code? except for the toString method, there are only mock methods that are labelled as 'TODO'.
what exactly do you need help with?

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 
what code? except for the toString method, there are only mock methods that are labelled as 'TODO'. what exactly do you need help with?

say for example
the method

public int size() {
// TODO
_data.size(); //returns the size of the hashmap right. how should i code it when
// the size return 0 , does it have to have a if else to check the zero?
return 0;
}

CodeJava1
Newbie Poster
4 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

have you tried coding it?

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

No, the size is the size. You can just return it, regardless of whether it's zero or more.
The return 0; is in there because the compiler will generate an error if that method doesn't return something. When you put in the correct code you can discard the return 0;

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 
have you tried coding it?

yes

CodeJava1
Newbie Poster
4 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: