This repository acts as a personal archive for my solutions to EdX course *Data Structures and Software Design* from PennX.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

  1. /*
  2. * SD2x Homework #5
  3. * This class represents a single rating for a movie.
  4. * Please do not change this code! Your solution will be evaluated using this version of the class.
  5. */
  6. public class UserMovieRating implements Comparable<UserMovieRating> {
  7. protected String movie;
  8. protected int userRating;
  9. public UserMovieRating(String movie, int userRating) {
  10. this.movie = movie;
  11. this.userRating = userRating;
  12. }
  13. public String getMovie() {
  14. return movie;
  15. }
  16. public int getUserRating() {
  17. return userRating;
  18. }
  19. @Override
  20. public boolean equals(Object obj) {
  21. if (this == obj)
  22. return true;
  23. if (obj == null)
  24. return false;
  25. if (getClass() != obj.getClass())
  26. return false;
  27. UserMovieRating other = (UserMovieRating) obj;
  28. if (movie == null) {
  29. if (other.movie != null)
  30. return false;
  31. } else if (!movie.equals(other.movie))
  32. return false;
  33. if (userRating != other.userRating)
  34. return false;
  35. return true;
  36. }
  37. @Override
  38. public int compareTo(UserMovieRating other) {
  39. return this.userRating - other.userRating;
  40. }
  41. }