hi,

public Record get(VideoObj v) {
    // TODO
if((v ==null)  || (v==""))
    return null;
else
 return ??;
  }

Recor and VideoObj are classes. if the methos return type is Record, can someone tell me what should I return?

thanks

Recommended Answers

All 9 Replies

an instance of Record

an instance of Record

So do i have to create a instance in the method
like
Record r = new Record(VideoObj video, int numOwned, int numOut, int numRentals);

so in the else part it will be return r;
is it? but what about the parameters for the Record metho? that is the only method that class has

thanks

I don't really understand what you mean. you need to create a valid instance of Record (since I don't know your record class, I am not making assumptions of how that looks like) by calling (on of) the constructor(s) of that class, and returning that instance.

what do you mean by 'the parameters for the Record metho? that is the only method that class has'.

can you post that code here? and put it between Code tags, it makes it a lot easier to read.

I don't really understand what you mean. you need to create a valid instance of Record (since I don't know your record class, I am not making assumptions of how that looks like) by calling (on of) the constructor(s) of that class, and returning that instance.

what do you mean by 'the parameters for the Record metho? that is the only method that class has'.

can you post that code here? and put it between Code tags, it makes it a lot easier to read.

the Record Class method

final class Record {
  /**
   * The video.
   * @invariant <code>video != null</code>
   */
  VideoObj video;
  /**
   * The number of copies of the video that are in the inventory.
   * @invariant <code>numOwned > 0</code>
   */
  int numOwned;
  /**
   * The number of copies of the video that are currently checked out.
   * @invariant <code>numOut <= numOwned</code>
   */
  int numOut;
  /**
   * The total number of times this video has ever been checked out.
   * @invariant <code>numRentals >= numOut</code>
   */
  int numRentals;

  /**
   * Initialize all object attributes.
   */
  Record(VideoObj video, int numOwned, int numOut, int numRentals) {
    this.video = video;
    this.numOwned = numOwned;
    this.numOut = numOut;
    this.numRentals = numRentals;
  }
  /**
   * Return a shallow copy of this record.
   */
  public Record copy() {
    return new Record(video,numOwned,numOut,numRentals);
  }
  /**
   * Return a string representation of the object in the following format:
   * <code>"video [numOwned,numOut,numRentals]"</code>.
   */
  public String toString() {
    StringBuilder buffer = new StringBuilder();
    buffer.append(video);
    buffer.append(" [");
    buffer.append(numOwned);
    buffer.append(",");
    buffer.append(numOut);
    buffer.append(",");
    buffer.append(numRentals);
    buffer.append("]");
    return buffer.toString();
  }
}
Record(VideoObj video, int numOwned, int numOut, int numRentals) {
    this.video = video;
    this.numOwned = numOwned;
    this.numOut = numOut;
    this.numRentals = numRentals;
  }

this is your constructor. you'll have to create a new instance of Record and return that, since you specified a constructor, your compiler will no longer find a default constructor (except if you add one yourself) so you'll have to pass all the parameters.

you have to have something like this:

return new Record(video,numOwned,numOut,numRentals);

and I don't mean: just copy paste this. this is the return of the copy method in your Record class. I don't know your project well enough to know where to get the other information.
A good way would be to keep an array(List) of Records somewhere. when you need to return that Record, go search this array for a Record having that video object attached to it, and return that instance.
if there isn't one: create it, add it to the list, and return it.

Record(VideoObj video, int numOwned, int numOut, int numRentals) {
    this.video = video;
    this.numOwned = numOwned;
    this.numOut = numOut;
    this.numRentals = numRentals;
  }

this is your constructor. you'll have to create a new instance of Record and return that, since you specified a constructor, your compiler will no longer find a default constructor (except if you add one yourself) so you'll have to pass all the parameters.

you have to have something like this:

return new Record(video,numOwned,numOut,numRentals);

and I don't mean: just copy paste this. this is the return of the copy method in your Record class. I don't know your project well enough to know where to get the other information.
A good way would be to keep an array(List) of Records somewhere. when you need to return that Record, go search this array for a Record having that video object attached to it, and return that instance.
if there isn't one: create it, add it to the list, and return it.

there is

private final Map<VideoObj,Record> _data = new HashMap<VideoObj,Record>();

in the class where the method
public Record get(VideoObj v) is

can i get the details for the return new Record(video,numOwned,numOut,numRentals); from "Map<VideoObj,Record> _data = new HashMap<VideoObj,Record>" ???

yes. Just get the Record linked to the VideoObj and return that one

yes. Just get the Record linked to the VideoObj and return that one

i didn't get it???

you have a HashMap filled with combinations of Video_obj Objects and Record Objects.
you have a Video_obj object, just search in your Map if there is an element which has that Video_object as a key.

if so, use that element, if not, create a new instance of Record, store that new combination in the HashMap and return that Record instance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.