Make a Class Comparable by One Field
easyQuestion 529Comparable<Movie> is an interface from the Java library with a single method, compareTo. A class that implements it tells Java how to put its objects in order, and then Arrays.sort can sort an array of them. Complete compareTo so movies are ordered by year, oldest first.
Requirements:
1. compareTo(Movie other) returns a negative number when the year of this movie is earlier than the year of the other movie, zero when the two years are equal, and a positive number when it is later.
2. Only the sign matters, so subtracting the two years is enough here. Integer.compare works as well.
3. Compare the years only. The title plays no part.
Do NOT write a main method.
Expected output
Night Train (1979) Red Harbor (2009) Paper Kites (2016)
= newline. The output ends with a newline, so print one after the last line.
Hints2 available
Sign in to use hintsTopics
InterfacesClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.