I'm having a little problem with trying to create an equals object that overrides the object equals method if the id numbers are the same.
It's the only problem i'm having, other than that, my program runs fine. Here's the code:
public class Movie { private String rating; private int ID; private String title; public Movie() { rating = "No rating"; title = "No title"; ID = 00000; } public Movie(String theTitle,String theRating, int theID) { if (theRating == null || theTitle == null || theID < 0) { System.out.println("Fatal Error creating Movie."); System.exit(0); } rating = theRating; title = theTitle; ID = theID; } public Movie(Movie originalObject) { rating = originalObject.rating; title = originalObject.title; ID = originalObject.ID; } public String getRating() { return rating; } public String getTitle() { return title; } public int getID() { return ID; } public void setRating(String newRating) { if (newRating == null) { System.out.println("Fatal Error setting Movie rating."); System.exit(0); } else rating = newRating; } public void setTitle(String newTitle) { if (newTitle == null) { System.out.println("Fatal Error setting Movie title."); System.exit(0); } else title = newTitle; } /** Precondition newID is a non-negative number. */ public void setID(int theID) { if (theID < 0) { System.out.println("Fatal Error setting Movie ID."); System.exit(0); } else ID = theID; } public String toString() { return ("Title: " + title + "\nRating: " + rating + "\nID#: " + ID); } public double calcLateFee(int dayLate) { return 2.0*dayLate; } public int equals(int theID) { if(ID == theID) { System.out.print("These movies are identical"); } return ID; } public boolean equals(Movie otherObject) { if(otherObject == null) return false; else if (getClass() != otherObject.getClass()) return false; else { Movie otherMovie = (Movie)otherObject; return ( (rating.equals(otherMovie.rating)) && (title.equals(otherMovie.title)) && (ID==otherMovie.ID) ); } } }