Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write code in the file Movie.java to implement a class called Movie with the fol

ID: 3737637 • Letter: W

Question

Write code in the file Movie.java to implement a class called Movie with the following fields (use the exact names): name: a string for the name of the movie; year: an integer for the year the movie was released; director: a string for the director's name; description: a string for a short description; ratings: an integer value ranging from 1 (horrible) to 5 (the best movie ever). Your class should also contain the following methods: a constructor that takes as an argument the movie's name; getter and setter methods for every field. Assume all inputs are valid; toString: should return the string representation of this movie with the movie's name, year and ratings; equals: with the following signature public boolean equals (Object other). Returns true if this object is the same as other object. Two objects are equal if they have the same name, director, and were released at the same year; compareTo: with the following signature public int compareTo(Movie other). Returns 0 if this movie's name is lexicographically equal to other movie's name; -1 If this movie's name is less than the other movie's name lexicographically; 1 If this movie's name is greater than the other movie's name lexicographically.

Explanation / Answer

public class Movie implements Comparable { private String name; private int year; private String director; private String description; private int rating; public Movie(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String getDirector() { return director; } public void setDirector(String director) { this.director = director; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public int getRating() { return rating; } public void setRating(int rating) { this.rating = rating; } @Override public String toString() { return "name='" + name + ''' + ", year=" + year + ", rating=" + rating; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Movie movie = (Movie) o; return name.equals(movie.name) && director.equals(movie.director) && year == movie.year; } @Override public int compareTo(Movie other) { return name.compareTo(other.name); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote