// *** Do you need to add an import statement here? *** /** * Lab #4 * CS 2334, Section 0?? * DATE GOES HERE *

* This class models the Movie ADT. *

* @author Group #?? * @version 1.0 */ public class Movie implements Comparable // Q. #3 Something has to be // added to the end of this // class declaration. { /** The title of the Movie represented by this class. */ private String title; /** The release date of the movie. */ private int year; /** * This is the default constructor for the class Movie. */ public Movie() { year = 0; title = ""; } /** * This is the constructor for the class Movie. * It instantiates the class with user supplied values. *

* @param title The title of the movie. * @param year The release date of the movie. */ public Movie(String title, int year) { this.title = new String( title ); this.year = year; } /** * Returns the title of the movie. *

* @return The title of the movie as a string. */ public String getTitle() { return title; } /** * Returns the year of the movie. *

* @return The year of the movie as a int. */ public int getYear() { return year; } /** * This method returns the attributes of this movie as * a single string. *

* @return String representing the * contents of this object. */ public String toString() { return new String( "Title: " + title + "\n" + "Year: " + year + "\n"); } /** * This method compares an instance of Movie with * this instance of Movie to see if they are equal. *

* Algorithm:
* Compare the title of the movies. If it is the same, * then compare the year of the movies. *

* @param obj The object we are comparing * this instance of Movie with. * @return Returns true if the two instances are * equal, false otherwise. */ public boolean equals( Object obj ) { if( (obj instanceof Movie) == false ) { return false; } Movie other = (Movie)obj; // First compare the title of the movies. if( title.equals(other.title) == false) { return false; } // If the title is the same, handle the year. return year == other.getYear(); // Why does this work? } /** * This method compares an instance of Movie with * this instance of Movie to determine their relationship. *

* Algorithm:
* Compare the title of the movies. If it is the same, * then compare the year of the movies. *

* @param other The object we are comparing * this instanceof Movie with. * @return Returns negative integer if this object is less then obj, * zero if the this object is equal to obj, * positive integer if this object is greater than obj. */ public int compareTo( Object obj ) { Movie other = (Movie)obj; // First compare the title of the movies if( title.compareTo( other.getTitle() ) != 0 ) { return title.compareTo( other.getTitle() ); } // If the title is the same, handle the year. return year - other.getYear(); //Why does this work?? } }