Question: Create a public class Movie in java with private instance variables String title and int year. The class should declare that it implements the Comparable

Create a public class Movie in java with private instance variables String title and int year. The class should declare that it implements the Comparable interface, and should provide the following: A constructor that takes 2 arguments: a String and an int (in that order) for initializing title and year. A method that satisfies the Comparable interface. Movies should be compared first by title and then by year.

Methods getTitle() and getYear() that do the right thing. An equals() method that is compatible with the method that satisfies the Comparable interface. A toString() method that prints Movie followed by 1 space followed by the title followed by 1 space followed by open-parenthesis followed by the year followed by close-parenthesis. Example: Movie The Maltese Falcon (1941)

A public static method getTestMovies(), which returns an array of 10 unique Movie instances. They dont have to be real movies its ok to make them up. The 0th and 1st array elements must be 2 movies with the same title but from different years (e.g. The Thomas Crown Affair 1968 and The Thomas Crown Affair 1999, or True Grit 1969 and True Grit 2010). The 2nd and 3rd elements (counting from 0) must be 2 movies with different titles but from the same year (e.g. The Martian 2015 and Bridge of Spies 2015). The 4th and 5th elements must be 2 different objects that represent the same movie (same title and same year). A hashCode() method. Use the following: public int hashCode() { return title.hashCode() + year; }

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!