Question: FINISH ALL TODOS // TODO: complete the methods /** * Immutable Data Class for video objects. * Comprises a triple: title, year, director. * *
FINISH ALL TODOS
// TODO: complete the methods /** * Immutable Data Class for video objects. * Comprises a triple: title, year, director. * * @objecttype Immutable Data Class * @objectinvariant * Title is non-null, no leading or final spaces, not empty string. * @objectinvariant * Year is greater than 1800, less than 5000. * @objectinvariant * Director is non-null, no leading or final spaces, not empty string. */ final class VideoObj implements Comparable { /** @invariant non-null, no leading or final spaces, not empty string */ private final String _title; /** @invariant greater than 1800, less than 5000 */ private final int _year; /** @invariant non-null, no leading or final spaces, not empty string */ private final String _director;
/** * Initialize all object attributes. * Title and director are "trimmed" to remove leading and final space. * @throws IllegalArgumentException if any object invariant is violated. */ VideoObj(String title, int year, String director) { // TODO _title = null; _year = 0; _director = null; }
/** * Return the value of the attribute. */ public String director() { // TODO return "director"; }
/** * Return the value of the attribute. */ public String title() { // TODO return "title"; }
/** * Return the value of the attribute. */ public int year() { // TODO return -1; }
/** * Compare the attributes of this object with those of thatObject. * @param thatObject the Object to be compared. * @return deep equality test between this and thatObject. */ public boolean equals(Object thatObject) { // TODO return false; }
/** * Return a hash code value for this object using the algorithm from Bloch: * fields are added in the following order: title, year, director. */ public int hashCode() { // TODO return -1; }
/** * Compares the attributes of this object with those of thatObject, in * the following order: title, year, director. * @param thatObject the Object to be compared. * @return a negative integer, zero, or a positive integer as this * object is less than, equal to, or greater thatObject. * @throws ClassCastException if thatObject has an incompatible type. */ public int compareTo(Object thatObject) { // TODO return -1; }
/** * Return a string representation of the object in the following format: * "title (year) : director". */ public String toString() { // TODO return "El Mariachi (1996) : Rodriguez"; } }
import junit.framework.Assert; import junit.framework.TestCase;
// TODO: complete the tests public class VideoTEST extends TestCase { public VideoTEST(String name) { super(name); } public void testConstructorAndAttributes() { String title1 = "XX"; String director1 = "XY"; String title2 = " XX "; String director2 = " XY "; int year = 2002;
VideoObj v1 = new VideoObj(title1, year, director1); Assert.assertSame(title1, v1.title()); Assert.assertEquals(year, v1.year()); Assert.assertSame(director1, v1.director());
VideoObj v2 = new VideoObj(title2, year, director2); Assert.assertEquals(title1, v2.title()); Assert.assertEquals(director1, v2.director()); }
public void testConstructorExceptionYear() { try { new VideoObj("X", 1800, "Y"); Assert.fail(); } catch (IllegalArgumentException e) { } try { new VideoObj("X", 5000, "Y"); Assert.fail(); } catch (IllegalArgumentException e) { } try { new VideoObj("X", 1801, "Y"); new VideoObj("X", 4999, "Y"); } catch (IllegalArgumentException e) { Assert.fail(); } }
public void testConstructorExceptionTitle() { try { new VideoObj(null, 2002, "Y"); Assert.fail(); } catch (IllegalArgumentException e) { } try { new VideoObj("", 2002, "Y"); Assert.fail(); } catch (IllegalArgumentException e) { } try { new VideoObj(" ", 2002, "Y"); Assert.fail(); } catch (IllegalArgumentException e) { } }
public void testConstructorExceptionDirector() { // TODO }
public void testHashCode() { Assert.assertEquals (-875826552, new VideoObj("None", 2009, "Zebra").hashCode()); Assert.assertEquals (-1391078111, new VideoObj("Blah", 1954, "Cante").hashCode()); }
public void testEquals() { // TODO }
public void testCompareTo() { // TODO }
public void testToString() { // TODO } }
Step by Step Solution
There are 3 Steps involved in it
It looks like the question is incomplete There are many TODO comments indicating areas where you need to complete the implementation details of the VideoObj class and its test suite Below is a summary ... View full answer
Get step-by-step solutions from verified subject matter experts
