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

Suppose you want to have an application to keep track of all the movies you\'ve

ID: 3737305 • Letter: S

Question

Suppose you want to have an application to keep track of all the movies you've seen. The first step is to define a class that represents a Movie and all the information you want to store about it. 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

Please find my implementation of Movie Class.

public class Movie {

   private String name, director, description;

   private int year, rating;

   public Movie(String name) {

       this.name = name;

   }

   public String getName() {

       return name;

   }

   public void setName(String name) {

       this.name = name;

   }

   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 getYear() {

       return year;

   }

   public void setYear(int year) {

       this.year = year;

   }

   public int getRating() {

       return rating;

   }

   public void setRating(int rating) {

       this.rating = rating;

   }

   public boolean equals(Object obj) {

       if (this == obj)

           return true;

       if (obj == null)

           return false;

       if (getClass() != obj.getClass())

           return false;

       Movie other = (Movie) obj;

       if (director == null) {

           if (other.director != null)

               return false;

       } else if (!director.equals(other.director))

           return false;

       if (name == null) {

           if (other.name != null)

               return false;

       } else if (!name.equals(other.name))

           return false;

       if (year != other.year)

           return false;

       return true;

   }

   public int compareTo(Movie other) {

       if(other.getName().compareTo(name) == 0) {

           return 0;

       } else if(other.getName().compareTo(name) > 0) {

           return 1;

       }

       return -1;

   }

}

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