Question: /** * Utility class for Inventory. Fields are mutable and package-private. * Does not override equals or hashCode . * * @objecttype Mutable Data Class

/** * Utility class for Inventory. Fields are mutable and package-private. * Does not override equals or hashCode. * * @objecttype Mutable Data Class */ final class Record { /** * The video. * @invariant video != null */ VideoObj video; /** * The number of copies of the video that are in the inventory. * @invariant numOwned > 0 */ int numOwned; /** * The number of copies of the video that are currently checked out. * @invariant numOut <= numOwned */ int numOut; /** * The total number of times this video has ever been checked out. * @invariant numRentals >= numOut */ 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: * "video [numOwned,numOut,numRentals]". */ public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append(video); buffer.append(" ["); buffer.append(numOwned); buffer.append(","); buffer.append(numOut); buffer.append(","); buffer.append(numRentals); buffer.append("]"); return buffer.toString(); } }

RECORDTEST

import junit.framework.Assert; import junit.framework.TestCase;

public class RecordTEST extends TestCase { public RecordTEST(String name) { super(name); }

public void testCopy() { // be sure to test that copy returns a NEW reference! VideoObj video = new VideoObj( "A", 2000, "B" ); Record r1 = new Record( video, 20, 10, 300 ); Record r2 = r1.copy(); Assert.assertTrue( r1 != r2 ); Assert.assertTrue( r1.toString().equals(r2.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!