Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help!!!! We have written the following Movie class below, and we want to be able to use the Collections. sort method to sort an

image text in transcribedimage text in transcribed

please help!!!!

We have written the following Movie class below, and we want to be able to use the Collections. sort method to sort an ArrayList. We want to sort by the title instance variable, and we want to break ties by the year instance variable. However, our code doesn't work, and we have no idea why. TASK: Fix the bug(s) in our code. EXAMPLE: After running the following lines of code: 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) 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)o).year && // 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions

Question

Identify five strategies to prevent workplace bullying.

Answered: 1 week ago