Question: Java We have written the following Movie class below, and we want to be able to use the Collections. sort method to sort an ArrayList

JavaJava We have written the following Movie class below, and we wantto be able to use the Collections. sort method to sort an

We have written the following Movie class below, and we want to be able to use the Collections. sort method to sort an ArrayList movies = new ArrayList ;. movies.add(new Movie("Good Burger", 1997)); movies.add(new Movie("The Lord of the Rings: The Fellowship of the Ring", 2001)); movies.add(new Movie("Fast Five", 2011)); Collections. sort(movies) ; for (Movie m : movies) { System.out.println(m): We will print the following: (Fast Five, 2011) (Good Burger, 1997) (The Lord of the Rings: The Fellowship of the Ring, 2001) HINT: We asked a tutor for help by submitting a ticket to the lab queue, and the tutor suggested we look into how to properly implement the Comparable interface. Tutors are so helpful and kind 1 class Movie { // instance variables private final String title; private final int year; // constructor public Movie(String t, int y) { if(t == null) { this.title = ""; } else { this.title = t; this.year = y; // instance methods public String getTitle() { return this.title; public int getYear() { return this.year; public String toString() { return "(" + this.title + "," + this.year + ")"; public boolean equals(Object o) { return (o instanceof Movie) && // check if o is a Movie this.year == ((Movie)) .year && Il check years for equality this.title.equals(((Movie)o).title); // check titles for equality

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!